Thursday, July 2, 2015

Re: multi table query with cross reference table

OK, i found the right query - now i just need to modify it into cakephp orm


SELECT Matches....
Seasons...
OpMatches...

FROM matches Matches


LEFT JOIN seasons Seasons ON (Seasons.id = (Matches.season_id) AND Seasons.stage_id = (Matches.stage_id))

LEFT JOIN op_matches OpMatches ON (Matches.match_date = OpMatches.match_date) /* AND 
(Matches.team_home = t.op_team_name OR Matches.team_home = OpMatches.team_home OR Matches.team_away = t.op_team_name OR Matches.team_away = OpMatches.team_away))  */
WHERE Matches.odds_url is null
AND(  
((Matches.team_away OR Matches.team_home) IN (select t.op_team_name from Teams t where (t.ws_team_name=Matches.team_home OR t.ws_team_name=Matches.team_away) and (t.op_team_name=OpMatches.team_home OR t.op_team_name=OpMatches.team_away) ) )
/*OR Matches.team_away IN (select t.op_team_name from Teams t where t.ws_team_name=Matches.team_away and t.op_team_name=OpMatches.team_away) )*/
);

You'll notice - the 'AND' part of the query is in parens - how do I get cakephp to do that?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: