Advertisement
Guest User

Untitled

a guest
May 19th, 2012
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // User Model:
  2.  
  3. class User extends AppModel {
  4. var $actsAs = array('Containable');
  5.  
  6. public $belongsTo = array(
  7. 'Company' => array(
  8. 'className' => 'Company',
  9. 'foreignKey' => 'company_id'
  10. )
  11. );
  12.  
  13. public $hasOne = array(
  14. 'Membership' => array(
  15. 'className' => 'Membership',
  16. 'foreignKey' => 'user_id',
  17. 'dependent' => false
  18. )
  19. );
  20. }
  21.  
  22. // Company Model:
  23.  
  24. class Company extends AppModel {
  25. var $actsAs = array('Containable');
  26. public $displayField = 'name';
  27.  
  28. public $hasMany = array(
  29. 'User' => array(
  30. 'className' => 'User',
  31. 'foreignKey' => 'company_id',
  32. 'dependent' => false
  33. )
  34. );
  35.  
  36. }
  37.  
  38. // Membership:
  39.  
  40. class Membership extends AppModel {
  41. var $actsAs = array('Containable');
  42.  
  43. public $belongsTo = array(
  44. 'User' => array(
  45. 'className' => 'User',
  46. 'foreignKey' => 'user_id'
  47. )
  48. );
  49. }
  50.  
  51. // Example Data:
  52. $this->User->contain('Company', 'Membership);
  53. $users = $this->User->find('all');
  54.  
  55. (int) 2 => array(
  56. 'User' => array(
  57. 'password' => '*****',
  58. 'id' => '10',
  59. 'company_id' => '0',
  60. 'company_contact' => '',
  61. 'email' => 'a@a.com',
  62. ),
  63. 'Company' => array(
  64. 'id' => null,
  65. 'name' => null,
  66. 'email' => null,
  67. 'contact_name' => null,
  68. 'contact_number' => null,
  69. 'contact_email' => null,
  70. 'created' => null
  71. ),
  72. 'Membership' => array(
  73. 'id' => null,
  74. 'user_id' => null,
  75. 'membership_type_id' => null,
  76. 'created' => null,
  77. 'expires' => null,
  78. 'renewed_on' => null,
  79. 'notes' => null
  80. )
  81. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement