Hi, I''m trying to implement logical deletion on my model by extending the has_many association, in a code like this: class Post < ActiveRecord::Base has_many :comments do def self.comments find :all, :conditions => ''confirmed is not null'' end end end where confirmed is a datetime field on my database. The problem is that when I call Post#comments I''m getting the usual find :all query. Has anyone implemented logical deletion by extending the has_many association? Thanks in advance, Marcos --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-01 09:01 UTC
Re: Logical deletion by extending has_many associations
On 1 Apr 2008, at 04:35, VM wrote:> > Hi, > > I''m trying to implement logical deletion on my model by extending the > has_many association, in a code like this: > > class Post < ActiveRecord::Base > has_many :comments do > def self.comments > find :all, :conditions => ''confirmed is not null'' > end > end > endThat would give you the ability to say some_post.comments.comments (although you don''t need the self. ) Why not just do this at the top level? ie has_many :comments, :conditions => ... Fred> > > where confirmed is a datetime field on my database. > > The problem is that when I call Post#comments I''m getting the usual > find :all query. > > Has anyone implemented logical deletion by extending the has_many > association? > > Thanks in advance, > Marcos > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Fred, Now I understand what I did but that''s no quite what I was trying to achieve. My goal was say some_post.comments and that would return only the comments where the confirmed field wasn''t null. Thanks for your answer. []''s Marcos On Apr 1, 6:01 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1 Apr 2008, at 04:35, VM wrote: > > > > > Hi, > > > I''m trying to implement logical deletion on my model by extending the > > has_many association, in a code like this: > > > class Post < ActiveRecord::Base > > has_many :comments do > > def self.comments > > find :all, :conditions => ''confirmed is not null'' > > end > > end > > end > > That would give you the ability to say some_post.comments.comments > (although you don''t need the self. ) > Why not just do this at the top level? ie > has_many :comments, :conditions => ... > > Fred > > > > > where confirmed is a datetime field on my database. > > > The problem is that when I call Post#comments I''m getting the usual > > find :all query. > > > Has anyone implemented logical deletion by extending the has_many > > association? > > > Thanks in advance, > > Marcos--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred, Now I''ve got it: has_many :comments, :conditions => ''confirmed_at is not null'' And that does what I need. Thank you, Marcos On Apr 1, 12:53 pm, VM <marco...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Fred, > > Now I understand what I did but that''s no quite what I was trying to > achieve. My goal was say some_post.comments and that would return only > the comments where the confirmed field wasn''t null. > > Thanks for your answer. > > []''s > Marcos > > On Apr 1, 6:01 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 1 Apr 2008, at 04:35, VM wrote: > > > > Hi, > > > > I''m trying to implement logical deletion on my model by extending the > > > has_many association, in a code like this: > > > > class Post < ActiveRecord::Base > > > has_many :comments do > > > def self.comments > > > find :all, :conditions => ''confirmed is not null'' > > > end > > > end > > > end > > > That would give you the ability to say some_post.comments.comments > > (although you don''t need the self. ) > > Why not just do this at the top level? ie > > has_many :comments, :conditions => ... > > > Fred > > > > where confirmed is a datetime field on my database. > > > > The problem is that when I call Post#comments I''m getting the usual > > > find :all query. > > > > Has anyone implemented logical deletion by extending the has_many > > > association? > > > > Thanks in advance, > > > Marcos--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---