开发者

Convert this SQL to cakephp find()

开发者 https://www.devze.com 2023-04-05 23:46 出处:网络
How can I write this SQL using cakephp find() SELECT a.user_id FROM answers a INNER JOIN answers a1 O开发者_运维百科N a1.question_id=1 AND a1.answer_value=\'Pooch\'

How can I write this SQL using cakephp find()

SELECT a.user_id FROM answers a
INNER JOIN answers a1 O开发者_运维百科N a1.question_id=1 AND a1.answer_value='Pooch'
INNER JOIN answers a2 ON a2.question_id=2 AND a2.answer_value='Peach'
GROUP BY a.user_id

Thanks in advance


You can use ad hoc joins or set up a self-referential model association. The former may be the easiest option because it's just building the SQL you already know and understand. :-)


There is a good section of the cookbook that shows you how to join tables, that dont automatically happen through your associations (hasOne, hasMany) etc.

http://book.cakephp.org/view/1047/Joining-tables


You can use converter by dogmatic69 here : http://cakephptutor.wordpress.com/2013/02/25/convert-sql-query-to-cakefind/

0

精彩评论

暂无评论...
验证码 换一张
取 消