2017-05-29 81 views
0
  • 我有一個品牌的產品。產品表中的brand_id。Cakephp得到兒童相關數據

  • 一個品牌有一個圖像集合。

  • 圖像在表格中有ID,product_id和路徑。

在產品索引中,您將獲得具有相關品牌數據的實體,如下所示。你不能去任何更深我想要什麼比這

$product->brands[0]['image_id']; 

爲了獲取路徑,我希望能夠去是這樣的:

$product->brand->image['path']; 

目前產品指標得到它的東西像這樣:

$this->paginate = [ 
     'contain' => ['Brands'] 
    ]; 
    $products = $this->paginate($this->Products); 

    $this->set(compact('products')); 
    $this->set('_serialize', ['products']); 

讓我怎麼接近「子查詢」或東西也得到了圖像表數據(產品的次要關聯,通過品牌)

我該如何解決這個問題?

回答

1

要得到更深層次的關聯,修改您的查詢選項:

'contain' => [ 
    'Brands' => ['Images'] 
] 
+2

延伸閱讀:** HTTPS://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html #eager-loading-associations-via-contain ** – ndm

+0

這就是它,謝謝 – mewc