This project is archived and is in readonly mode.
Association proxies using class methods with named scopes
-
Frederick Cheung
I think I understand why this is. I setup User has_many posts, post has a named_scope called active.
When you do
User.last.posts.activeThen active is called on the association proxy, and method missing on the association proxy knows that if you call :foo on it and :foo is a named scope on the parent then it should call that scope on itself (ie the named scope is called with proxy_scope set to the association proxy)
When you do
class Post def self.class_method active end end User.last.posts.class_methodThen the active method is called on class Post, not the association proxy and so the named scope is called with proxy_scope set to Post, not the association proxy.
The association proxy wraps the call to class_method in a with_scope with the conditions so if class_method does a find then it will execute inside the with_scope block and everything is fine. But if it just invokes a scope upon which a find is done later then that find is executed outside the with_scope and so everything falls to pieces.
-
Diego Algorta
I think my patch on #1960 fixes this.
-
Repository
- State changed from new to resolved
(from [a9aa18fdcdf3146ccbdecff71e52015f26a0f0b7]) Fixed bug that makes named_scopes forgot current scope
Signed-off-by: rick technoweenie@gmail.com [#1960 #1677 state:resolved] http://github.com/rails/rails/co...