[Rails] delete_if doesn't work for has_and_belongs_to_many

John Anderson ardour at semiosix.com
Wed Aug 9 08:12:00 GMT 2006


On Tue, 2006-08-08 at 21:44 +0200, Daniel Waite wrote:
> > Given that there are various operations that can be performed,
> > including just manipulating the array/collection in memory, why should
> > AR have to choose one operation from those available, and make as many
> > constructs as possible perform it?  Why does there have to be a
> > "winner", when the situation is already such that there's at least one
> > way to do all of the things in question?
> 
> I think what David is saying (because it's a bit cryptic) is that you 
> already have the functionality you need via model#delete(:conditions => 
> [])

Not at all. That was clear to me.

> without having to step on the toes of other, original array methods.

That's exactly what I find puzzling. For me it's not stepping on the
toes of other methods, it's making sure that if you're masquerading as
someone else then you do a proper job.

For Array, delete_if is a more general form of delete - I can implement
the delete functionality in terms of delete_if (Well, except for the
returning of the block if the item isn't found). But I can't do that
with an AR collection. That strikes me as very odd.

> Given this, why bother with forcing ActiveRecord to chew up more methods 
> than is needed?

Because if you don't do a good job masquerading as someone else, someone
will see through your disguise.

In this case AssociationProxy implements method_missing and forwards
delete_if to its underlying Array.

> (My co-worker does this kind of stuff and it irks me to 
> no end. It's called #update_attributes you fool! Sorry. :)

What kind of stuff? And what irks you, exactly?

bye
John




More information about the Rails mailing list