Instead of extracting a specific piece of a named_scope's proxy options, I would probably elect to use a more flexible, object-oriented solution using inheritance.
http://gist.github.com/71604 On Fri, Feb 27, 2009 at 9:37 AM, Luke Redpath <ljredp...@gmail.com> wrote: > > In my current project, I have an association model that has various > flags available. To keep the implementation of these flags > encapsulated, I created named_scopes for each flag and use these > scopes for finding and creating. > > This model sits between two others as the join model in a > has_many :through association. I actually wanted various > has_many :through associations that use the same join model but > different scopes. Unfortunately has_many :through doesn't have > a :scope option; I could use :conditions to get it working but I've > now broken the encapsulation I aimed for when I introduced the named > scopes and created unnecessary duplication. > > Hopefully this rather contrived example should make it clear what I'm > aiming for. > > http://gist.github.com/71585 > > And my initial implementation, currently in use in our app (tries to > extend ActiveRecord in the least-intrusive way): > > https://gist.github.com/9d7f86e27014ef5df280 > > And now, my attempt to do it properly as a patch to ActiveRecord, with > a test. > > http://gist.github.com/71587 > > I don't expect this patch to be completely ready for inclusion; there > are probably other things to consider such as, do you just want to > pull the :conditions from the proxy? Is there anything else to pull > in? Could this be written in a better way (probably, my knowledge if > the AR internals is slim). > > Any thoughts? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---