Friday, August 1, 2014

CakePHP3 - How to get the data od second level relation ship table.

Hi,
I have a Company table, User table and employees table.
The company details are there in company table.
In employee table there is one company_id and user_id fields. The relationship is as follows.
One company can have multiple employees, and each employee should have a record in users table.

Actually When I am finding data of company , I need it to contain all the employees with their user data on it.
To access the company data.

I tried the following methods but getting error.

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Users.company_id' in 'where clause'


================================
Company Model
========
public function initialize(array $config) {
       
         $this->hasMany('Employees');
         $this->hasMany('Users', [ 'through' => 'Employees']);
   
    }
Employees Model
===============
public function initialize(array $config) {
       
        $this->belongsTo('Companies');
        $this->belongsTo('Users');
       
   
    }

Users Model
===========
$this->hasMany('Employees');

Would you please help me to find a solution?
Regards,
Jipson

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: