class Model_Music extends Orm\Model { protected static $_table_name = 'mini_lists_music'; protected static $_primary_key = array('list_id'); protected static $_has_one = array( 'lists' => array( 'model_to' => 'Model_Lists', 'key_from' => 'list_id', 'key_to' => 'list_id', ), ); }
Model_Music::find('all');
// eager loading, using joins: $music = Model_Music::find('all', array('related' => array('lists'))); // or $music = Model_Music::find()->related('lists')->get(); // or use lazy loading, it won't use joins but query a relation once requested // first get a "music", 1 query without join $music = Model_Music::find('first'); // now request the lists, which will do another query without join automaticly $lists = $music->lists;
Thanks, this was exactly what i was looking for.Jelmer Schreuder wrote on Wednesday 6th of April 2011:It won't auto-include any relations, there's a couple of options to get them:
// eager loading, using joins: $music = Model_Music::find('all', array('related' => array('lists'))); // or $music = Model_Music::find()->related('lists')->get(); // or use lazy loading, it won't use joins but query a relation once requested // first get a "music", 1 query without join $music = Model_Music::find('first'); // now request the lists, which will do another query without join automaticly $lists = $music->lists;
It looks like you're new here. If you want to get involved, click one of these buttons!