# Logical deletion by extending has\_many associations

**URL:** <https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506>\
**Category:** Rails\
**Created:** [April 1, 2008, 5:36am UTC](https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506 "2008-04-01T05:36:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VMVMVM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ce73a5/32.png) [@VMVMVM](https://www.ruby-forum.com/u/VMVMVM)\
**Post date:** [April 1, 2008, 5:36am UTC](https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506/1 "2008-04-01T05:36:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VMVMVM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ce73a5/32.png) [@VMVMVM](https://www.ruby-forum.com/u/VMVMVM)\
**Post date:** [April 1, 2008, 11:01am UTC](https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506/2 "2008-04-01T11:01:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VMVMVM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ce73a5/32.png) [@VMVMVM](https://www.ruby-forum.com/u/VMVMVM)\
**Post date:** [April 1, 2008, 10:28pm UTC](https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506/3 "2008-04-01T22:28:42Z")

</div>

Fred,

Now I’ve got it:

has\_many :comments, :conditions =\> ‘confirmed\_at is not null’

And that does what I need.

Thank you,  
Marcos

---

<div class="post-metadata">

**Author:** ![VMVMVM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ce73a5/32.png) [@VMVMVM](https://www.ruby-forum.com/u/VMVMVM)\
**Post date:** [April 1, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/logical-deletion-by-extending-has-many-associations/133506/4 "2008-04-01T17:53:41Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
