【发布时间】:2020-10-23 21:53:59
【问题描述】:
我遇到了急切加载问题
我有两个模型:
class Provider extends Model
{
/**
* Get the currency record associated with the provider.
*/
public function currency()
{
return $this->hasOne('App\Currency', 'tabcur', 'poucur')->where('tabcol','$DEV');
}
class Currency extends Model
{
/**
* Get the providers record associated with the currency.
*/
public function provider()
{
return $this->belongsTo('App\Provider', 'tabcur', 'poucur');
}
当我尝试这个时:
Provider::first()->currency
成功了
但是,如果我尝试这个:
Provider::with('currency')->first()
字段货币为空
currency: null,
谁能帮帮我?
编辑 1
我试过了
>>> DB::connection()->enableQueryLog()
>>> App\Provider::with('currency')->first()
>>> DB::getQueryLog()
我有这个 App\Provider::with('currency')->first()
[
[
"query" => "select * from PROVIDER FETCH FIRST 1 ROWS ONLY",
"bindings" => [],
"time" => 18.74,
],
[
"query" => "select * from CURRENCY where tabcol = ? and CURRENCY.tabcur in (?)",
"bindings" => [
"$DEV",
" ",
],
"time" => 33.94,
],
]
但它是钢铁“空”
【问题讨论】:
-
您的 Provider 表中有
currency列吗?如果是,则更改关系名称。 -
不,我的提供者表中没有“货币”列
标签: laravel eager-loading