[Solar-talk] new model & a many to many question
Rodrigo Moraes
rodrigo.moraes at gmail.com
Wed Mar 14 18:04:11 PDT 2007
Hi,
I finally finished what I was doing to try the new model (had to hurry
a bit :) and got already a set of models working with it. I have basic
question about how to set up a many to many relationship:
I have three tables:
- platform - game platforms
- game - game titles
- game2platform - many to many mapping of the two tables above.
So, when I need a list of games in a given platform, I started with
this in the Platform model:
$this->_addRelated('has_many', 'games',
array(
'foreign_model' => 'Tipos_Model_Game_Game2Platform',
'foreign_col' => 'platform_id',
)
);
And then the Game2Platform model has two 'has_one' definitions: for a
platform and a game.
I'm not sure however about how to setup the relationship to be able to
order the related games from a platform (by title, creation, etc), or
in sql words have something like this as result:
SELECT *
FROM game2platform
JOIN game ON game2platform.game_id = game.id
WHERE game2platform.platform_id =1
ORDER BY game.title
LIMIT 0, 30;
Any advice?
rodrigo
More information about the solar-talk
mailing list