Skip to content

Destroying a non-permanent record with permanent record associations? #65

Open
@aried3r

Description

@aried3r

I have a model A which is non permanent which has_many :bs, dependent: :destroy. There is also a foreign key on B, called a_id, so I have referential integrity.

Now, of course, if I try to destroy an instance of A, this crashes, because my permanent B still exists when .destroy is called on it.

--- Caused by: ---
PG::ForeignKeyViolation:
  ERROR:  update or delete on table "A" violates foreign key constraint "fk_rails_feff868667" on table "B"
  DETAIL:  Key (id)=(589) is still referenced from table "B".

Is there a way to propagate the :force option down to the Bs? I know this is a very specific use case since I don't want to remove the referential integrity and indeed want to delete the otherwise permanent Bs, when I delete an A.

But since I saw that the reverse case, if A was permanent and B wasn't, is covered by this gem and documented in the specs, I thought I might ask. I didn't dig deep enough into the code yet to see if this is possible to achieve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions