Wish List: has_many :dependent => {}

I am after a nice way to disable (not destroy, delete nor nullify) all
associated records. I’m a hoarder, I don’t want to get rid of anything
but I
want to stop records being visible.

I have a disabled boolean in my tables and if I disable the top record
in
the association (say the association is 5-6 levels deep), I would like
to
cleanly disable its children.

I’ve looked in the source to see how AR collects all the records but
couldn’t easily track it back.

The way I’m thinking is to extend …

has_many :products do
def disable
products = all(:conditions => ‘’, :include => associations)
products.each do
## but here it gets messy
end

end
end

Does anyone have a nicer solution to this?

Thank you

-ants

Sent from my iPhone

On Apr 6, 2011, at 5:05 AM, Ants P. [email protected]
wrote:

products = all(:conditions => '', :include => associations)
products.each do
 ## but here it gets messy
end

end
end

Does anyone have a nicer solution to this?

I would set the has_many dependency to delete/destroy then in the model
products redefine what the delete/destroy method does.

def delete
#set disable Boolean
end

This not only works for your cascading dependencies but also if you call
the delete method from an object of products.

B.

Yes, that’s nice. Thanks for that. For some reason, I didn’t think the
has_many would call my delete but I guess it does.

Again, thanks.

-ants