Hey, I have got an action that should retrieve all rows where the created_at column matches the current date, but I want another condition in there saying that the column parent_id should equal to nil (:parent_id => nil). I have been trying all sorts, but don''t get any results. Any suggestions? def new @year = Time.now.year @month = Time.now.month @day = Time.now.day @date = ("#{@year}-#{@month}-#{@day}") @logo = Logo.find(:all, :conditions => ["created_at = ?", @date]) end Cheers -- 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 -~----------~----~----~----~------~----~------~--~---
Logo.find(:all, :conditions => {:created_at => @date, :parent_id => nil}) Logo.find(:all, :conditions => ["created_at = ? AND parent_id = ?", Date.today, nil]) On Oct 16, 9:11 am, Rajeev Kala <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey, > > I have got an action that should retrieve all rows where the created_at > column matches the current date, but I want another condition in there > saying that the column parent_id should equal to nil (:parent_id => > nil). I have been trying all sorts, but don''t get any results. Any > suggestions? > > def new > @year = Time.now.year > @month = Time.now.month > @day = Time.now.day > @date = ("#{@year}-#{@month}-#{@day}") > > @logo = Logo.find(:all, :conditions => ["created_at = ?", @date]) > end > > Cheers > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
On 10/16/07, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey, > > I have got an action that should retrieve all rows where the created_at > column matches the current date, but I want another condition in there > saying that the column parent_id should equal to nil (:parent_id => > nil). I have been trying all sorts, but don''t get any results. Any > suggestions? > > def new > @year = Time.now.year > @month = Time.now.month > @day = Time.now.day > @date = ("#{@year}-#{@month}-#{@day}") > > @logo = Logo.find(:all, :conditions => ["created_at = ?", @date]) > endWell, you can include the parent_id condition with: :conditions => ["created_at = ? and parent_id is null", @date] But your date stuff worries me. created_at is a timestamp, so you''ll never get a match (unless the time on the timestamp is 00:00:00). If you want all the timestamps for a date, you need to find timestamps in a 24-hour range, right? Something like: :conditions => ["created_at between ? and ? and parent_id is null", Date.today, Date.today+1] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Bloom wrote:> Logo.find(:all, :conditions => {:created_at => @date, :parent_id => > nil}) > > Logo.find(:all, :conditions => ["created_at = ? AND parent_id = ?", > Date.today, nil]) > > > On Oct 16, 9:11 am, Rajeev Kala <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thanks mate did the trick. -- 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> On 10/16/07, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Well, you can include the parent_id condition with: > > :conditions => ["created_at = ? and parent_id is null", @date] > > But your date stuff worries me. created_at is a timestamp, so you''ll > never get a match (unless the time on the timestamp is 00:00:00). If > you want all the timestamps for a date, you need to find timestamps in > a 24-hour range, right? > > Something like: > > :conditions => ["created_at between ? and ? and parent_id is null", > Date.today, Date.today+1]Oh no my created_at field only contains the date and not the time as well otherwise it would be a nightmare. Thanks anyways. -- 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 -~----------~----~----~----~------~----~------~--~---
On Oct 16, 9:44 am, Rajeev Kala <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Oh no my created_at field only contains the date and not the time as > well otherwise it would be a nightmare. Thanks anyways.Ok, but the RAILS convention is to use ''created_on'' for dates and ''created_at'' for dates and times. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kevin cline wrote:> On Oct 16, 9:44 am, Rajeev Kala <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Oh no my created_at field only contains the date and not the time as >> well otherwise it would be a nightmare. Thanks anyways. > > Ok, but the RAILS convention is to use ''created_on'' for dates and > ''created_at'' for dates and times.Ok I didn''t know that thanks for letting me know I''ll have to change that then. -- 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 -~----------~----~----~----~------~----~------~--~---