You will need to force an SQL JOIN by rebinding Robot HABTM Tag to Tag
belongsTo Robot, then use $this->Robot->Tag->find(...) with recursive = 2
(or you may use Containable behavior) to construct your desired SQL
statements.  If you have to do it through $this->Robot->find(...) you'll
need to rebind Robot hasOne Tag which I am not sure if it will get
everything you want.

See this post by teknoid for more details:
http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/

Lapinski


Xoubaman wrote:
> 
> 
> Robot HABTM Tag
> User hasMany Robot
> Robot belongsTo User
> 
> I want to get related robots based on his tags. More tags in common,
> more related.
> 
> So, whats the way to put this query using $this->Robot->find(...) or
> $this->Robot->RobotsTag->find(...)
> 
> SELECT count(tag_id) as total, Robots.*, Users.username
> FROM
> (`robots_tags` INNER JOIN robots ON (robots_tags.robot_id =
> robots.id))
> INNER JOIN users ON robots.user_id=users.id
> WHERE tag_id IN (1,2,3)
> GROUP BY robot_id
> ORDER BY total DESC
> LIMIT 4
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-make-this-query-the-Cake-way--tp25878312p25884721.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to