Laravel Eloquent ORM eager loading. Relation incorrectly returned as null -
Laravel Eloquent ORM eager loading. Relation incorrectly returned as null -
i have eloquent orm relationship defined follows:
productconfiguration:
public function product() { homecoming $this->belongsto('excel\products\product'); } public function currency() { homecoming $this->belongsto('excel\currencies\currency'); } product
public function productconfigurations() { homecoming $this->hasmany('excel\products\productconfiguration'); } public function producttype() { homecoming $this->belongsto('excel\products\producttype'); } i expect if next load product configurations of specified product type, related products, nested product type details , product configuration currency
$results = productconfiguration::with( array( 'product' => function($query) utilize ($product_type) { $query->where('product_type_id' , $product_type); }, 'product.producttype', 'currency' ) ) ->get(); however returned collection has 'product' set null. currency relationship there, product relationship not. can see outputted sql queries , query selects products retrieves right products if paste straight sql editor
select * `products` `products`.`id` in ('12', '13') , `product_type_id` = '1' am right think results query should included in collection, or there obvious flaw in thinking?
i think don't want accomplish that. getting productconfiguration products of certain_type.
so in case have configuration has other type product null because limited results product 1 has product type.
i might wrong, wanted productconfiguration belongs product type of certain_type. in case should utilize wherehas:
$results = productconfiguration:: with('product', 'product.producttype', 'currency')-> wherehas('product', function($q) utilize ($product_type) { $q->where('product_type_id', '=', $product_type); })->get(); laravel eloquent eager-loading
Comments
Post a Comment