title: Rails: How to use dependent: :destroy in rails?
body: <p>I have 2 models as describes below.</p>
  
  <pre><code>class EmpGroup &lt; ActiveRecord::Base
    belongs_to :user
    has_many :emp_group_members, dependent: :destroy
  end
  </code></pre>
  
  <p>and </p>
  
  <pre><code>class EmpGroupMember &lt; ActiveRecord::Base
    belongs_to :emp_group
    belongs_to :user
  end
  </code></pre>
  
  <p>now the problem is whenever I tried to destroy a group then I received a error as below.</p>
  
  <pre><code>PG::ForeignKeyViolation: ERROR:  update or delete on table "emp_groups" violates foreign key constraint "fk_rails_bd68440021" on table "emp_group_members"
  DETAIL:  Key (id)=(1) is still referenced from table "emp_group_members".
  </code></pre>
  
  <p>What I'm missing?</p>