Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aried3r opened this issue Jan 14, 2016 · 0 comments
Open

Comments

@aried3r
Copy link

aried3r commented Jan 14, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant