Search code examples
ruby-on-railshas-and-belongs-to-many

habtm relationship does not support :dependent option


Is it true that HABTM relationships do not support the :dependent option?

class Person < ActiveRecord::Base
  has_and_belongs_to_many :posts, :dependent => :destroy
end

I am trying rails edge.


Solution

  • Yep, It doesn't support it. See the docs. Generally habtm is meant only for very very simple cases and if you start needing more complex things you should switch to has_many :through.