If you want to stick to your database, you might use has and belongs to many relation. In employee.php:
public $hasAndBelongsToMany = [
'Office'=> [
'foreign_key' => 'employees_id',
'joinTable' => 'postings',
'associationForeignKey' => 'offices_id',
]
];
Then you can get office from employee model.
What I really want to suggest is that put a column office_id
in employees
table, and put
$public $belongsTo = ['office'];
in your employee model.
PS: Brackets []
is supported in php 5.4 or newer , if you are using php 5.3 or lower, you may want to replace it with array()
.