Closed masterzeus05 closed 2 years ago
I believe that reason for this is avoiding errors with foreign key constraints in the database. So it actually may be a feature (but not sure).
Please provide your EvilSeed configuration.
Possible workarounds: instruct evil-seed to dump Person, Cars, and PersonCarBorrows separately.
The configuration is something like
EvilSeed.configure do |config|
config.root("Person", id: ids) do |root|
root.exclude(/\.translations/)
end
config.root("Car") do |root|
root.exclude(/\.translations/)
root.exclude(/car\.person_car_borrows\.person\..*/)
end
end
So the problem might actually be related to this exclude root.exclude(/card\.person_car_borrows\.person\..*/)
?
The only reason I do that exclude is that it is not of my interest to export all "Persons" that a Car is borrowed to, but now that I'm looking at it, maybe the exclude should be root.exclude(/card\..*/)
to avoid the PersonCarBorrows altogether from the Cars?
EDIT: Just to add that Person has defined in it
has_many :person_car_borrows, dependent: :restrict_with_exception
EDIT2: Ok I think that the problem is just related with the order of the configuration? It just worked now by changing the order, so thanks!
Got it. This is feature to keep referential integrity.
If you don't interested in persons that a Car is borrowed to, then you won't have them in the database. In that case, if you try to insert record to person_car_borrows
with identifier that is missing from persons
(and you have foreign key in place) then database will throw an error that this value violates referential integrity. So it is better to nullify foreign key value if we know that we're not going to reference anything.
Hey! Sorry to bother again, but this time I found an issue that I don't know if it is really a bug or just something about my schema or configuration.
For example, I have 3 models,
Person
,Car
,PersonCarBorrow
, and thePersonCarBorrow
has defined:And when dumping this schema, with root on
Person
, the PersonCarBorrow will have thePerson
foreign keyperson_id
NULL, and theCar
foreign key with the correct value.My gems versions:
After a little search, I think the issue is related with this line relation_dumper#149, as the foreign_key is nullified because of the condition on
excluded = ... || reflection.name == inverse_reflection
. A fork of this gem already made a change related to this shippio/evil-seed-41025192b46649cf43af91d7fd7a80358a9e7379.Thank you for your help.