【问题标题】:Laravel live server won't work with eager loadingLaravel 实时服务器不适用于急切加载
【发布时间】:2013-07-31 15:47:42
【问题描述】:

我有一些代码在我的本地机器(WAMP,PHP 5.4.3)上运行良好,但在生产服务器(CentOS,PHP 5.4.11)上却没有,我不明白为什么,有问题代码行是:

$sharedList = SharedList::with('itemList')
                          ->where('unique_url', '=', $uniqueURL)
                          ->first();

如果我删除 with() 急切加载,那么它运行没有问题,如果我不这样做(并且我不需要在我的本地机器上),那么我会得到这个:

Argument 2 passed to Illuminate\Database\Eloquent\Relations\BelongsTo::match() 
must be an instance of Illuminate\Database\Eloquent\Collection, instance of 
ItemList given, called in /home/mgc/public_html/test/vendor/laravel/framework
/src/Illuminate/Database/Eloquent/Builder.php on line 474 and defined 

/home/site/public_html/test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php

line 154: public function match(array $models, Collection $results, $relation)

来自 SharedList 模型的相关关系信息是:

class SharedList extends Ardent {

public function itemList()
{
    return $this->belongsTo('ItemList', 'list_id');
}

不知道是不是大小写问题,在with()方法中我试过ItemList、itemlist和itemList。

这可能是一个 Ardent 问题,但我尝试将 extend Ardent 替换为 extend Eloquent 无济于事。

【问题讨论】:

    标签: php laravel laravel-4 eloquent ardent


    【解决方案1】:

    您的with('itemList') 是正确的,因为它应该是建立关系的函数的名称。我感觉问题可能出在之后的 where 子句上。尝试延迟加载。

    $sharedList = SharedList::where('unique_url',$uniqueURL)->get();
    $sharedList->load('itemList');
    

    【讨论】:

    • 嗨,这引发了完全相同的错误,我想这取决于某种关系设置
    猜你喜欢
    • 2021-10-08
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2014-08-13
    • 2021-04-23
    • 2018-10-15
    • 1970-01-01
    相关资源
    最近更新 更多