staudenmeir / belongs-to-through

Laravel Eloquent BelongsToThrough relationships
MIT License
1.17k stars 91 forks source link

Call to undefined method BelongsToThrough::getOwnerKeyName() #86

Closed lmeysel closed 1 year ago

lmeysel commented 1 year ago

PHP 8.2.6 laravel/framework: 10.15.0 staudenmeir/belongs-to-through 2.13

I have a model File, belongs to User (via field created_by_id) and User belongs to (natural) Person. I want to list the files with the person who created it:

So, I was creating a belongsToThrough relation as $this->belongsToThrough(Person::class, [User::class], foreignKeyLookup: [User::class => 'created_by_id']);

But the query fails with BadMethodCallException: Call to undefined method Znck\Eloquent\Relations\BelongsToThrough::getOwnerKeyName()

Looking into the code, it appears getOwnerKeyName does not exist.

staudenmeir commented 1 year ago

Hi @lmeysel, Please share the exception's whole stacktrace. What query are you executing?

lmeysel commented 1 year ago

Hi thanks for your fast reply. I probably should have pasted the trace right with the issue, then I would have seen the source of my problem occurs while doing something totally different and just "misused" the relation.

Problem does not persist, now everything works fine.