[英]Laravel belongsTo return null
我有兩種模式
字模型:
class Word extends Model
{
public function pos()
{
return $this->belongsTo(Pos::class);
}
}
和PoS模型 :
class Pos extends Model
{
//
protected $table = 'pos';
public $timestamps = false;
}
現在在控制器中我想獲取word
和pos
關系,但是當我指定列時pos
關系返回null
調節器
$word = Word::with(['pos'])->whereId( $vocabulary->word_id)->get(['id', 'word', 'surface', 'gloss', 'example','sound_url'])->first();
請注意當我使用查詢而不指定列完美地工作
$word = Word::with(['pos'])->whereId( $vocabulary->word_id)->first();
我已經嘗試過使用addselect
, with closure
但相同的結果
也許嘗試將pos_id
添加到該columns數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.