@maitrefrantz I have edited now
Oct 12, 2016
5
Level 1
Eloquent relation gives wrong result
Hi I have three tables
user
----------------------
id name
user_products
-------------------
id user_id product_id
Products
--------------------------
id product_name
Relations are done like following
Class User{
public function UserProducts(){
return $this->hasMany('UserProducts', 'id', 'user_id');
}
}
Class UserProducts{
public function Products(){
return $this->belongsTo('Products', 'product_id', 'id');
}
}
Now my query is this
Users::with(array(
'UserProducts' => function ($query) use($productId) {
$query->where("product_id","=", $productId);
$query->with('Products');
}))->get();
The problem is the where query on the relation works well, but returns the records which is not = $productId Mentioned in the where clause.
Has anyone gone through this situation before. Please help
Please or to participate in this conversation.