Ruby on Rails
Monday, February 17, 2014
I have several years of Rails expirience and this little bit ALWAYS gets me:
class Foo < ActiveRecord::Base
has_many :bars
end
class Bar < ActiveRecord::Base
belongs_to :foo
end
# after creating some foos and bars
foo.bars.delete_all #=>
UPDATE bars SET foo_id = NULL WHERE foo_id = $1
Yes I know I can set :dependant => :delete_all
but what's resoning behind this default behaviour? Is it just a legacy stuff?
I'd expect foo.bars.delete_all to act the same as Bar.delete_all or Bar.where(foo_id: foo.id).delete_all regardles of the :dependant option.
anyone knows why the default behaviour here is to nullify keys?
-- class Foo < ActiveRecord::Base
has_many :bars
end
class Bar < ActiveRecord::Base
belongs_to :foo
end
# after creating some foos and bars
foo.bars.delete_all #=>
UPDATE bars SET foo_id = NULL WHERE foo_id = $1
Yes I know I can set :dependant => :delete_all
but what's resoning behind this default behaviour? Is it just a legacy stuff?
I'd expect foo.bars.delete_all to act the same as Bar.delete_all or Bar.where(foo_id: foo.id).delete_all regardles of the :dependant option.
anyone knows why the default behaviour here is to nullify keys?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9487b425-9ea6-4fd3-b89b-373be55b826c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment