我定义为一个雄辩的ORM的关系如下:Laravel Eloquent ORM急切加载。关系不正确地返回空
ProductConfiguration:
产品
public function productConfigurations()
{
return $this->hasMany('Excel\Products\ProductConfiguration');
}
public function productType()
{
return $this->belongsTo('Excel\Products\ProductType');
}
我希望如果我做了以下我将加载指定产品类型的所有产品配置,以及相关产品的嵌套ed产品类型详细信息和产品配置货币
$results = ProductConfiguration::with(
array(
'product' => function($query) use ($product_type) {
$query->where('product_type_id' , $product_type);
},
'product.productType',
'currency'
)
)
->get();
但是,返回的集合将'product'设置为NULL。货币关系在那里,但产品关系不是。我可以看到输出的SQL查询和选择产品,如果我直接粘贴到我的SQL编辑器
select * from `products`
where `products`.`id` in ('12', '13')
and `product_type_id` = '1'
我是正确地认为该查询的结果应包括在检索正确的产品查询我的收藏,还是在我的思想中有一些明显的缺陷?
发生什么,如果你删除''' 'product.productType''''和它添加到你'''' product''''功能:'' '$查询 - >与( 'productType')'''?希望有所帮助。 – ArjanSchouten 2014-10-20 09:40:09
同样的结果。产品是NULL。它的奇怪,因为正确的SQL quries正在运行,但结果并没有出现在收集 – 2014-10-20 09:53:55