On 27 Mar., 07:20, Tam Kbe <[email protected]> wrote:
> Hello,
>
> Is there a way to add automatic condition to all active record find
> methods?
>
> I have an attribute in all my tables something like "effective_end_date"
> so that I don't delete records but I keep them by setting
> effective_end_date so I want to put condition is all my find queries
> effective_end_date Is null or effective_end_date > Time.now. I don't
> want to type this for every single query so I was wondering if it's
> possible to automate it.

Yes, you can use default_scope: 
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002258
It supports the same options as the find methods.

--
Best regards,
David Knorr
http://twitter.com/rubyguy
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to