IsraelOrtuno / Eavquent

EAV modeling package for Laravel and Eloquent – This package is abandoned, please use this fork https://github.com/rinvex/attributes
63 stars 14 forks source link

Doesn't work Lazy Eager Loading #47

Closed Feniksss closed 6 years ago

Feniksss commented 7 years ago

Hi. I try to load a fields by:

$test= Test::where('tests.id', $id)
                ->select('tests.*')->first();
$test->load('eav');

And I get an error: Call to undefined relationship [eav] on model [App\Test].

But if I use the construction 'with' in model: protected $with = ['eav']; - It's works correct. So, what's the problem? Thanks!

IsraelOrtuno commented 7 years ago

Laravel version?

Feniksss commented 7 years ago

5.3

brenjt commented 7 years ago

I am having the same issue on 5.3. I also do not see any logic in the code to handle 'eav' relationship loading.

IsraelOrtuno commented 7 years ago

It's located in the scope class. Probably needs a few changes to work with 5.3. This was tested up to 5.2.

On Tue, 6 Dec 2016 at 01:21, brenjt notifications@github.com wrote:

I am having the same issue on 5.3. I also do not see any logic in the code to handle 'eav' relationship loading.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/IsraelOrtuno/Eavquent/issues/47#issuecomment-265022096, or mute the thread https://github.com/notifications/unsubscribe-auth/ABr_yWB9GP1kOj9DEhKeh457fJaM_Ilnks5rFKqfgaJpZM4K9GC_ .

brenjt commented 7 years ago

The issue seems to be here: $eagerLoads = array_merge($eagerLoads, $model->getAttributeRelations()); getAttributeRelations() is returning an empty array when booting. But when called after boot it returns the correct data.

brenjt commented 7 years ago

I found the problem for me at-least. It had to do with inheritance. If i was overwriting the newFromBuilder and wanted to load a dynamic class instance for my model then the scopes would never be applied resulting in it never loading those relationships.

I think this could be easily resolved if the ->load('eav') worked correctly. I'll see if I can find a solution.