Logical deletion by extending has_many associations

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

On 1 Apr 2008, at 04:35, VM wrote:

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

Fred,

Now I’ve got it:

has_many :comments, :conditions => ‘confirmed_at is not null’

And that does what I need.

Thank you,
Marcos

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 C. [email protected]