DmitryTsepelev / ar_lazy_preload

Lazy loading associations for the ActiveRecord models
MIT License
677 stars 24 forks source link

Add failing test case for `preload_associations_lazily` for relation with includes called #40

Closed PikachuEXE closed 3 years ago

PikachuEXE commented 4 years ago

This is actually for a potential bug I found and I don't know how to fix Bug: If #includes is called before #preload_associations_lazily, any association not mentioned in includes will not be loaded in a batch when called

See test case for

it "loads association of association automatically when `includes` called"
coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 299


Totals Coverage Status
Change from base Build 298: 0.04%
Covered Lines: 748
Relevant Lines: 780

💛 - Coveralls
coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 295


Totals Coverage Status
Change from base Build 293: 3.9%
Covered Lines: 745
Relevant Lines: 747

💛 - Coveralls
DmitryTsepelev commented 4 years ago

Thank you for catching that! I'll try to dig into it during the next few days

DmitryTsepelev commented 4 years ago

The problem is that when includes is called, Rails loads users association as part of posts relation initialization. It means that when users relation is loaded, preloads_associations_lazily? returns false and context is not created. I wonder if we could somehow detect preloading and check if parent association can be lazily loaded (we could do it in the Preloader, but it only has an access to an Array of Post models, not relation).

I guess we should add this issue to the README for now 🙂

PikachuEXE commented 4 years ago

Let's update the readme for now Not an urgent issue for me (I just swap remove calls to includes)

DmitryTsepelev commented 4 years ago

I've added a line and mentioned this issue, so let's keep it open 🙂

DmitryTsepelev commented 3 years ago

Fixed by #48