2

I have a table Bmp with these associations

class Bmp < ActiveRecord::Base
  #associations
     has_many :subareas, dependent: :destroy
     belongs_to :scenario

and another table Subareas

class Subarea < ActiveRecord::Base
  #associations
      belongs_to :scenarios
      belongs_to :soil
      belongs_to :bmp

however, when I try to delete a bmp, it should delete my subarea as well, but it is not doing so.

  def destroy
    @bmp = Bmp.find(params[:id])
    @bmp.destroy

I don't see where I've messed up, any ideas are greatly appreciated!

Santi Gallego
  • 202
  • 1
  • 18

1 Answers1

0

Your subareas will still belongs to scenarios !! If you delete them associations will be broken between them .

  • Remove "belongs_to :scenarios" in subarea.rb .

  • Add "has_many :subareas ,trough: :bmp" in scenario.rb .

This will maintain relations between subareas and scenarios but will put bmp "on the way " between them and will allow "chain destroy".

plombix
  • 396
  • 3
  • 13