This project is archived and is in readonly mode.
Returning Block on Association Extension Causes Proxy Owner To Load Target
-
Ken Collins
I forgot to mention that if you used the returning block inside of a controller (just anywhere outside of an association extension) that the SQL is just fine. The issue only seems to be when using the returning block in an association extensions.
ALSO, I have a type above... my example association method that shows that either use of returning should have been as follows.
module FooBarReturning def foo_bar_returning returning build do |c| # SELECT * FROM "articles" WHERE ("columns".user_id = 1) end end end -
Frederick Cheung
returning is a method activesupport adds to Object, so it's available everywhere. Except on an association proxy, because association proxies undef all their methods (so that they filter through to the target), including returning.
With returning you don't care who you call returning on though, so something like
Object.returning build do |c| ... endSeing as returning doesn't depending on who its called on (it's just injected everywhere for convenience), arguably you could just not undef it.
-
Ken Collins
Not sure what you are saying... returning works in the association extension but it just has ILL EFFECTS of loading the target. I am pretty sure Object.returning does the same.
-
Frederick Cheung
because returning is undeffed on the proxy, it has to load the array in order to call it. By calling it on Object you avoid that (the choice of Object is arbitrary). try it.
-
Ken Collins
OK, I will!
-
josh
- State changed from new to wontfix