Created
February 27, 2012 12:16
-
-
Save heptat/1923384 to your computer and use it in GitHub Desktop.
li3 relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// registrations model, foreign key is session_id and *not* venue_session_id: | |
class Registrations extends \lithium\data\Model { | |
public $belongsTo = array( | |
'VenueSessions' => array('key' => array('session_id' => 'id')), | |
// also tried this, which doesn't work: | |
// 'VenueSessions' => array('class' => 'VenueSessions', 'key' => 'session_id'), | |
); | |
... | |
} | |
// and VenueSessions model: | |
class VenueSessions extends \lithium\data\Model { | |
public $hasMany = array( | |
'Registrations' => array('class' => 'Registrations', 'key' => 'session_id') | |
); | |
... | |
} | |
// and then a query using the relationship: | |
$results = Registrations::find('all', array( | |
'conditions' => $conditions, | |
'with' => 'VenueSessions', | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment