Hello everyone :) I need to access an attribute directly into a find. Is that possible? For instance: Topics.find(:all, :conditions => expiration_date-1.hour + " < NOW( )") Here, expiration_date would be an attribute of Topics. Thank you ! -- 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 think you''d do something like this: Topics.find(:all, :conditions => ["expiration_date < ?", Time.now + 1.hour]) See http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001891&name=findfor more examples. Regards, Craig -- Craig Demyanovich Mutually Human Software http://mutuallyhuman.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 -~----------~----~----~----~------~----~------~--~---
It helps, thanks! But what if I have 2 conditions ? For instance, is this possible? Topics.find(:all, :conditions => ["expiration_date < ? AND attribute =", Time.now + 1.hours], yet_another_variable) Thank you! -- 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 -~----------~----~----~----~------~----~------~--~---
Topic.find(:all, :conditions => ["expiration_date < ? AND attribute = ?", Time.now + 1.hour, yet_another_variable]) In other words, everything goes in the conditions array. The first element is the SQL fragment. Every other element is a value to be substituted for a ? in the SQL fragment. Rails will properly quote strings and dates. Again, see the find docs [ http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001891&name=find] for examples. Also, the Rails Guides [ http://guides.rubyonrails.org ] are good, and the section on query conditions [ http://guides.rubyonrails.org/active_record_querying.html#conditions ] has more details. Regards, Craig -- Craig Demyanovich Mutually Human Software http://mutuallyhuman.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 -~----------~----~----~----~------~----~------~--~---