CakePHP3 'contain' doesn't retrieve 'belongsTo'

Viewed 24

A user has multiple products. Each product has a brand.

In the Products Table, I have a "brand_id" column.

For the moment there is no join when I do debug($user).

I would like a join between Brands and Products Tables (product.brand_id = brand.id). How can I solve this ?

(sorry for my english)

//Controller Users
    $users = TableRegistry::getTableLocator()->get('users');
    $user = $users->find('all')
            ->contain(['Products' => ['conditions' => ['id' => 25]]])
            ->first();
    debug($user); 


//Model Users
public function initialize(array $config)
{
    $this->hasMany('products');
}


//model Products
public function initialize(array $config)
{
    $this->belongsTo('brands');
}
1 Answers
Related