Skip to content

Instantly share code, notes, and snippets.

@heptat
Created February 27, 2012 12:16
Show Gist options
  • Save heptat/1923384 to your computer and use it in GitHub Desktop.
Save heptat/1923384 to your computer and use it in GitHub Desktop.
li3 relationship
<?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