Clearing dependent collections

I have a user model that owns messages :

class User < ActiveRecord::Base
has_many :messages , :dependent => :nullify
end

I’m using nullify so that when the user is deleted, the messages
continue to exist - they’re just marked as being ownerless.

However, calling user.messages.clear actually deletes all his
messages, which I was a little surprised at. I would have expected
it to just set the user_id on all his messages to null, given I’m not
using :dependent => :destroy/:delete.

Is this intentional? Is there an equivalent call which will just
disassociate the messages? (Obviously I could use something like
user.messages.each {|m| m.update_attribute(user_id, nil)} - is there
anything actually built in?)

Jon

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs