环境: PHP 8.1.4,Laravel 9
雄辩模型:市场模型,序列模型
序列模型属于市场模型。
// Sequence.php
public function market()
{
return $this->belongsTo(Market::class);
}市场表和序列表都有正确的数据。
问题是,序列模型无法正确访问其market。看起来$this->market()工作得很好,但是$this->market返回null。
// Some method in Sequence.php
private function loadCollection(): CandleCollection
{
dd($this->market(), $this->market);
return $this->collection = $this->market->createCandleCollection($this->label, $this->size);
}当我转储$this->market()时,它返回BelongsTo object和$this->market,它返回null。
另外,$this->market()->toSql()返回
select * from `markets` where `markets`.`id` is null奇怪的是,它昨天真的很好,而且我没有修改它的代码.;我相信未知的副作用会导致这种情况,但我从来没有经历过这些问题。任何洞察力的帮助..。
发布于 2022-04-08 03:18:23
对不起..。我刚发现有一个空的方法getAttribute($key)..。同事说他开了个玩笑。
https://stackoverflow.com/questions/71790970
复制相似问题