Support the ongoing development of Laravel.io →
Database Eloquent

I have a problem with using morphMany relations in combination with lists in my model. I do have a Meta model (morphMany) and a Resort model. The Resort model has a method metas() that just does this: return $this->morphMany('Meta', 'metable');

	public function metas()
	{
		return $this->morphMany('Meta', 'metable')->lists('value', 'key');
	}

Now what I want to have is a key/value list, just like I am able to do with hasMany: return $this->morphMany('Meta', 'metable')->lists('value', 'key'); But this doesn't work. If I use the same with hasMany on a different table, it works fine, so I assume there must be a difference between hasMany and morphMany in terms of the object structure.

The error I get is: Call to a member function addEagerConstraints() on a non-object [/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Builder.php, Line 471] (Laravel 4.2.8)

I hope any of you can help me with this issue.

Thanks a lot in advance.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.