I am trying to make the relationship between the tables, but can’t figure out what I doing wrong.
I read The documentations in cakephp3, and tons of post in stackoverflow, and still can’t get any result.
--------------------------
name |invoices |shares |
var |id |id |
var | |idBill |
--------------------------
The relationship should be from idBill in shares and id in invoices
class SharesTable extends Table {
public function initialize(array $config) {
parent::initialize($config);
$this->belongsTo('invoices', [
'className' => 'App\Model\Table\InvoicesTable',
'foreignKey' => 'idBill',
'targetForeignKey' => 'id'
]);
}
}
And in controller try to print the bill associate to the share like this:
public function view($id = null)
{
$share = $this->Shares->get($id, [
'contain' => []
]);
var_dump( $share->invoices );
$this->set('share', $share);
}
I just expect to print the bill but I always get null