0

I've got some code that has been working fine on my local machine (WAMP, PHP 5.4.3) but not on a production server (CentOS, PHP 5.4.11) and I can't see why, the offending line of code is:

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

if I remove the with() eager loading then this runs without issue, if I don't (and I don't need to on my local machine) then I get this:

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)

The relevant relationship info from the SharedList model is:

class SharedList extends Ardent {

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

I don't know if this is a capitalisation issue, in the with() method I have tried ItemList, itemlist and itemList.

It could be an Ardent issue, but I have tried replacing extend Ardent with extend Eloquent to no avail.

totymedli
  • 29,531
  • 22
  • 131
  • 165
Al_
  • 2,479
  • 7
  • 29
  • 43

1 Answers1

0

Your with('itemList') is correct, as it should be the name of the function setting up the relationship. I have a feeling the problem might be with the where clause coming after that. Try lazy eager loading.

$sharedList = SharedList::where('unique_url',$uniqueURL)->get();
$sharedList->load('itemList');
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1669496
  • 32,176
  • 9
  • 73
  • 65
  • Hi, That throws up the exact same error, I guess it's down to the relationship setup somehow – Al_ Aug 01 '13 at 14:28