Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // User Model:
- class User extends AppModel {
- var $actsAs = array('Containable');
- public $belongsTo = array(
- 'Company' => array(
- 'className' => 'Company',
- 'foreignKey' => 'company_id'
- )
- );
- public $hasOne = array(
- 'Membership' => array(
- 'className' => 'Membership',
- 'foreignKey' => 'user_id',
- 'dependent' => false
- )
- );
- }
- // Company Model:
- class Company extends AppModel {
- var $actsAs = array('Containable');
- public $displayField = 'name';
- public $hasMany = array(
- 'User' => array(
- 'className' => 'User',
- 'foreignKey' => 'company_id',
- 'dependent' => false
- )
- );
- }
- // Membership:
- class Membership extends AppModel {
- var $actsAs = array('Containable');
- public $belongsTo = array(
- 'User' => array(
- 'className' => 'User',
- 'foreignKey' => 'user_id'
- )
- );
- }
- // Example Data:
- $this->User->contain('Company', 'Membership);
- $users = $this->User->find('all');
- (int) 2 => array(
- 'User' => array(
- 'password' => '*****',
- 'id' => '10',
- 'company_id' => '0',
- 'company_contact' => '',
- 'email' => 'a@a.com',
- ),
- 'Company' => array(
- 'id' => null,
- 'name' => null,
- 'email' => null,
- 'contact_name' => null,
- 'contact_number' => null,
- 'contact_email' => null,
- 'created' => null
- ),
- 'Membership' => array(
- 'id' => null,
- 'user_id' => null,
- 'membership_type_id' => null,
- 'created' => null,
- 'expires' => null,
- 'renewed_on' => null,
- 'notes' => null
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement