I have two tables employees
and posting
.
employees
with fields id
,name
AND
postings
with fields id
,employee_id
,status
Now to retrieve all the employees(with posting details) whose Posting.status = 1
, I wrote in PostingsController.php
's view()
action:
$cond = array('Posting.status'=>1);
$e = $this->Employee->find('all',array('conditions' => $cond));
$this->set('emp',$e);
In Employee.php
model var $hasMany = 'Posting';
In Posting.php
model var $belongsTo = 'Employee';
But the above code generates an error like :
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Posting.status' in 'where clause'
Generated SQL:
SQL Query: SELECT `Employee`.`id`, `Employee`.`name` FROM `cakelab`.`employees` AS `Employee` WHERE `Posting`.`status` = 1
I am new to CakePhp joins, please guide me.
hasMany
or thebelongsTo
). 2. Yourrecursive
option is set to -1, somewhere. Please copy paste the relevant parts of the models. also, you mentioned that you are new to cake's join, it is transparent to the user if not used specifically - have you tapered with it anyway? – yossi