Created
August 25, 2016 19:54
-
-
Save danielolivaresd/146699b087a77784402f5eb7b768c59c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Device | |
belongs_to :car | |
end | |
class Car | |
has_one :device | |
end | |
# Rails adds foreign key constraints automatically, so sometimes (not sure when exactly), | |
# when you try to +destroy+ a Car, it will complain with a PG::ForeignKeyViolation: ERROR: ... | |
# We need to add a on_delete option from the database itself. | |
remove_foreign_key :devices, :cars | |
add_foreign_key :devices, :cars, on_delete: :nullify # Options are :nullify, :cascade and :restrict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment