Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:21:23+00:00 2026-06-14T07:21:23+00:00

I am using custom SQL to join two tables, apply some business logic to

  • 0

I am using custom SQL to join two tables, apply some business logic to dates, then use the results to hydrate a propel object (collection). Here’s my code:

$testtypes = TesttypeQuery::create()->find();

foreach ($testtypes as $testtype) {

  /* work out what most recent schedule */
  $con = \Propel::getConnection(SchedulePeer::DATABASE_NAME);
  $sql = "SELECT `schedule`.*, (`schedule`.`last` + INTERVAL `duration`.`weeks` WEEK + INTERVAL `duration`.`months` MONTH + INTERVAL `duration`.`years` YEAR) AS `dueDate` FROM `schedule` LEFT JOIN `duration` ON `schedule`.`duration_id` = `duration`.`id` HAVING `schedule`.`testtype_id` = {$testtype->getId()} AND `dueDate` < NOW() ORDER BY `dueDate` ASC LIMIT 1";
  $stmt = $con->prepare($sql);
  $stmt->execute();
  $formatter = new \PropelObjectFormatter();
  $formatter->setClass(SchedulePeer::OM_CLASS);
  $schedules = $formatter->format($stmt);

  // more stuff here ... 
}

This question comes in several parts, because there might be a completely better way of doing this – so please feel free to make suggestions other than just answering my specific questions:

  • I am using HAVING instead of WHERE so that I can use the aliased column dueDate, which I want to use as part of the check and order, as well as returning it as part of the result-set to use later. Is there a way to grab this value but still hydrate the propel object? When I use fetch() or other PDO methods on $stmt I can no longer use this with the call to format().
  • Alternatively is there a better way to do this with pure Propel?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:21:24+00:00Added an answer on June 14, 2026 at 7:21 am

    You should add some steps. This is the logical process:

    1. SQL call that does not include the extra columns
    2. Hydrate the object(s)
    3. SQL call the returns values for the extra columns
    4. Update the hydrated object(s) with the extra column values

    Hope this helps. Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some things I need to use custom SQL for. Just to start,
I am using a sql store procedure for custom paging. Now i want to
I'm using custom WordPress categories for some probably unintended functions, I will admit (things
i'm having some problems using a custom made function to search specific data from
I am using SQL Server 2008 and I'm trying to produce a custom xml
I am using Microsoft SQL Server 2008. While generating custom reports, I need to
I would like to do an outer join on a one-to-many relationship (using SQL
I'm trying to develop a custom report for trac using SQL. On one of
I am trying to find out if SQL Server express SSRS supports using custom
I'm using a many-to-many database with join tables connecting main data tables through foreign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.