Hi all, I''ve got an interesting problem. I''m dealing with a legacy database, and for one of my models I always want to ignore records that have a particular column set. I would like to pretend like they don''t exist. When I run MyModel.find() I don''t want them to show in the result set. I considered using after_find() to do this, but that gets called on every item in the found collection, not the entire collection. Is there some easy way to modify MyModel to insert a :conditions statement (or modify a pre-existing one) on all queries issued by the model? Ideally it would be transparent enough that the other models don''t need to know anything about it. Thanks! -Brent -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I''ve got an interesting problem. I''m dealing with a legacy database, > and for one of my models I always want to ignore records that have a > particular column set. I would like to pretend like they don''t exist. > When I run MyModel.find() I don''t want them to show in the result set. > > I considered using after_find() to do this, but that gets called on > every item in the found collection, not the entire collection. Is there > some easy way to modify MyModel to insert a :conditions statement (or > modify a pre-existing one) on all queries issued by the model? Ideally > it would be transparent enough that the other models don''t need to know > anything about it.perhaps... http://agilewebdevelopment.com/plugins/global_scope Or maybe this guy wrote his idea up. http://zargony.com/2007/08/13/scope_out-feature-default_scope --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> anything about it. > perhaps... > > http://agilewebdevelopment.com/plugins/global_scope > > Or maybe this guy wrote his idea up. > > http://zargony.com/2007/08/13/scope_out-feature-default_scopeZargony refers to the global_scope plugin. :+) That happens to *perfectly* solve my problem. Thanks for the tip! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---