I've been using Cake for some time, but recently hit a problem with
hasAndBelongsToMany.
I have a videogame database, I'm trying to add a tagging system to it.
I'm storing my tags in 3NF.
So I have a model for games which is binding Games to Tags with
hasAndBelongsToMany and also my Tag model binds back to Games with a
hasAndBelongsToMany. The Games model is also bound to some other
tables with belongsTo (e.g. Genre, Region, System etc,). Naturally I
have a join table called "games_tags" linking the many-to-many
relationship.
I want to query my system and get all games with a specific tag, and
this is where it falls down
If I do:
$this->Game->Tag->find('all', array('conditions' => array('Tag.name
=' => 'foo')));
It works but it doesn't join the other tables to Game, so I can't get
the Game's genre or system
$this->Tag->Game->find('all', array('conditions' => array('Tag.name
=' => 'foo')));
This fails with an error "Unknown column 'Tag.name' in 'where clause"
Either way it's not joining all the tables properly, it seems to do
two separate queries
This is so frustrating because if I was writing the SQL by hand I
would have this solved in a matter of minutes, but Cake removes any of
this freedom.
What am I doing wrong??? this is such an obvious thing to do
Thanks in advance
Ben
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment