Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. // into controller
  2.  
  3. $this->Jobcategory->find('all', array(
  4.     'contains' => array('UsersJobcategory'),
  5.     'recursive' => 1,
  6.     'conditions' => array(
  7.         'UsersJobcategory.type' => 'favorite',
  8.     ),
  9.     'fields' => array(
  10.         'UsersJobcategory.*'
  11.     )
  12. ));
  13.  
  14.  
  15. // SQL query
  16.  
  17. SELECT `Jobcategory`.`id`, `Jobcategory`.`category`, `Jobcategory`.`parent_category_id`, `Jobcategory`.`domain_id`, `Jobcategory`.`active`, `Jobcategory`.`created`, `Jobcategory`.`modified` FROM `jobcategories` AS `Jobcategory`   WHERE `UsersJobcategory`.`type` = 'favorite'    
  18.  
  19.  
  20. // Jobcategory model
  21.  
  22. class Jobcategory extends AppModel {
  23.  
  24.     var $name = 'Jobcategory';
  25.     var $recursive = 1;
  26.    
  27.     var $hasMany = array(
  28.  
  29.             'UsersJobcategory' => array(
  30.                 'className' => 'UsersJobcategory',
  31.                 'foreignKey' => 'jobcategory_id'
  32.             )
  33.     );
  34.  
  35.  
  36. // UsersJobcategory
  37.  
  38. class UsersJobcategory extends AppModel {
  39.    
  40.     var $name = 'UsersJobcategory';
  41.    
  42.     var $belongsTo = array(
  43.         'Jobcategory' => array(
  44.             'className' => 'Jobcategory',
  45.             'foreignKey' => 'jobcategory_id'
  46.         )
  47.     );
  48.  
  49.  
  50. // AppModel
  51.  
  52. class AppModel extends Model {
  53.     var $actsAs = array('Containable', 'Linkable.Linkable');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement