My destroy action is throwing this error:
Failure/Error: Deal.delete(params[:id])
ActiveRecord::InvalidForeignKey:
PG::ForeignKeyViolation: ERROR: update or delete on table "deals" violates foreign key constraint "fk_rails_cc6e075aca" on table "origin_airports"
The action:
def destroy
Deal.delete(params[:id])
redirect_to deals_path
end
I've found answers about this (such as this one) and adjusted my Deal
class thusly:
has_many :origin_airports, dependent: :destroy
has_many :origins, through: :origin_airports, source: :airport
But I still get the same error.
PS. The designated answer for the post referenced above says "Yet better option to respect data integrity is to set the CASCADE DELETE on the database level." I'd love to know how to do that.
Thanks all.