Kip
2010-Nov-03 14:25 UTC
Accessing (updating?) the proxy_scope chain for named_scope (Rails 2.3.x)
I have many named_scopes chained together in the normal way. So far so good. However in a couple of cases where: 1. The named scope is actually a correlated subquery and I need to pass additional scope into it sometimes. 2. Where the presence of a named scope in the chain should change the behaviour of a named_scope later in the chain Given: Product.price.volume.average_discount I''d like the named_scope :average_discount to be able to reach back in the proxy chain to see if :price is part of the chain (its an example only, not the actual use case ). And potentially ''adjust'' it. #scoped_methods isn''t it - that''s populated only when in with_scope. Question 1: How can I access to the current proxy chain from within a named_scope? Question 2: Can I modify the proxy_options (shudder I know) without some serious monkey patching? Yes, I realise I could add parameters to these lambdas, but its not very DRY to be passing in the same parameter to several methods in the chain either. Note I can''t always predict in advance what the scope chain will be - it can be derived based upon user input dynamically (think of a basic reporting system where the user specifies the attributes they want in a table). Any ideas or alternatives? --Kip -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.