How can I translate this SQL query into a propel query

181 Views Asked by At

I need to write this SQL query in Propel 2.0

SELECT RequestUser.userID, requests.requestID, requests.created, Responses.created, Responses.response, Responses.createdby_userID FROM requests 
LEFT JOIN requestusers RequestUser ON (requests.requestID=RequestUser.requestID)
LEFT JOIN responses Responses ON (requests.requestID=Responses.requestID AND RequestUser.userID=Responses.createdby_userID) 
WHERE requests.supportstatusID=3
and requests.requestid=50208;

Most important is the second join, it has multiple conditions.

I for the life of me cannot figure this out. Any ideas?

I have used the Criteria class to AddMultipleJoins() but to no avail.

$pendingRequests = RequestQuery::create($criteria)
    ->select(['RequestUser.UserId', 'Request.Id', 'Request.CreatedDate'])
    ->leftJoin('Request.RequestUser RequestUser')
    ->leftJoin('Request.Response Responses')// <------ I need this line to have multiple conditions
    ->filterBySupportStatusId(3)
    ->find();
1

There are 1 best solutions below

0
Kia Samouie On BEST ANSWER

Okay I figured it out using this:

->addJoinCondition('JoinName', 'LeftColumn=?', 'RightColumn')

This adds an extra condition to the join!