CakePHP获取关联
我有一个报价表,在产品表下面。Products表位于Markups表(外键为markup\u id)下 现在,当我尝试此代码时:CakePHP获取关联,php,cakephp,associations,Php,Cakephp,Associations,我有一个报价表,在产品表下面。Products表位于Markups表(外键为markup\u id)下 现在,当我尝试此代码时: $offersObject = $this->paginate($this->Offers->find('all') ->contain('Products'); 我得到的结果是: Array ( [0] => App\Model\Entity\Offer Object (
$offersObject = $this->paginate($this->Offers->find('all')
->contain('Products');
我得到的结果是:
Array
(
[0] => App\Model\Entity\Offer Object
(
[id] => 1
[store_id] => 1
[product_id] => 1
[price] => 150
[new_price] => 0
[status] => 1
[twid] => 70261
[magkod] => MAG
[product] => App\Model\Entity\Product Object
(
[id] => 1
[name] => BOSCH S3 41Ah 360A S3001
[markup_id] => 3
[created] => Cake\I18n\FrozenTime Object
(
[time] => 2018-01-08T14:30:38+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\FrozenTime Object
(
[time] => 2018-01-08T14:30:38+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[[repository]] => Products
)
)
问题是我实际上得到了markup_id,我需要的是Products表中的关联行
从my OffersTable.php:
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'INNER'
]);
ProductsTable.php
$this->hasMany('Offers');
$this->belongsTo('Markups', [
'foreignKey' => 'markup_id',
'joinType' => 'INNER'
]);
请告知。或者要求任何澄清。您可以使用嵌套数组加载嵌套关联:
$offersObject = $this->paginate($this->Offers->find('all')
->contain([
'Products' => [
'Markups'
]
]);
或者,可以使用点表示法表示嵌套关联:
$offersObject = $this->paginate($this->Offers->find('all')
->contain([
'Products.Markups'
]);
您可以使用嵌套数组加载嵌套关联:
$offersObject = $this->paginate($this->Offers->find('all')
->contain([
'Products' => [
'Markups'
]
]);
或者,可以使用点表示法表示嵌套关联:
$offersObject = $this->paginate($this->Offers->find('all')
->contain([
'Products.Markups'
]);
哦,天哪,你刚刚解决了我的问题,比你想象的还要多。谢谢你,好心的先生!哦,天哪,你刚刚解决了我比你想象的更多的问题。谢谢你,好心的先生!