This project is archived and is in readonly mode.
[patch] has many through eager loading problem
-
Andrew Roth
+1
-
Daniel X Moore
+1
I'm having the same problem.
←[4;35;1mProduct Load (126.0ms)←[0m ←[0mSELECT * FROM
productsWHERE (products.idIN (468,193,457,369,567,469,458,546,216,568,194,249,470,459,250, 195,471,218,460,515,251,196,461,516,197,561,462,550,495,198,617,584,496,463,573,452,199,519,453,365,497,200,520,366,454,521,543,367,477,466,279,510,499,455, 191,522,478,467,357,280,192,5,511,456) AND (products.status_id = 2 AND products.inventory_type_id = 1)) ←[0m ←[4;36;1mProduct Load (5.0ms)←[0m ←[0;1mSELECT * FROMproductsWHERE (products.id= 495) ←[0m ←[4;35;1mProduct Load (4.0ms)←[0m ←[0mSELECT * FROMproductsWHERE (products.id= 499) ←[0m ←[4;36;1mProduct Load (4.0ms)←[0m ←[0;1mSELECT * FROMproductsWHERE (products.id= 515) ←[0mThose extra three that load individually don't match the conditions.
-
Daniel X Moore
I have a checked out copy of rails source, the applied patch, and the failing test. I would like to contribute a fix for this, but I need a little help getting pointed in the right direction.
I'm looking at active_record/association_preload.rb around
preload_has_many_association, but I'm having trouble really getting to the bottom of things. If anyone can link me to a guide about ActiveRecord internals then I would greatly appreciate it.Thanks for any help.
-
Rizwan Reza
- Milestone changed from 2.x to 2.3.6
-
Grant Ammons
- Importance changed from to Low
The issue is that loading the association is not taking into account the :conditions when loading the :through association.
Created a patch that will join the associated model and apply the conditions to the :through query. This is the only real way I can see fixing this, because as it stands right now, AR will grab the associated :through model(s) first, and then grab the association, but by then it's too late!
-
Grant Ammons
Fixed patch slightly.
-
Neeraj Singh
- State changed from new to open
@Grant I could not apply this patch against 2-3-stable branch. Did you create the patch against 2-3-x or rails master?
-
Grant Ammons
Oh, that patch is against master. Attached is a patch for 2-3-stable.
-
Neeraj Singh
- Assigned user set to Pratik
+1 I applied the fix for rails master and it works fine. Did not try 2-3-stable fix but that looks good too.
-
Grant Ammons
- Title changed from has many through eager loading problem to [patch] has many through eager loading problem
-
José Valim
- Assigned user changed from Pratik to José Valim
- Milestone cleared.
-
Repository
- State changed from open to resolved
(from [17650e394fae26984d506fd0f705bc32e5a5de27]) Eager loading :through associations will join the :source model if there are :conditions. [#2362 [patch] has many through eager loading problem state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/17650e394fae26984d506fd0f705bc... -
Repository
- State changed from resolved to committed
(from [0963774c0a6a58ba13ac0ff4763527ea7d994c0a]) fixes #2362 [patch] has many through eager loading problem, eager loading :through associations will join the :source model if there are :conditions
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/0963774c0a6a58ba13ac0ff4763527...
