Overriding an associated key still creates a new instance in the database #35
Labels
bug
Something isn't working
enhancement
New feature or request
help wanted
Extra attention is needed
Hey there, firstly awesome revival of this package, it's made E2E testing our systems so much smoother than previous approached! But we've recently run into a bug/issue with creating instances:
In the
create
method of the Factory class, the method first gets the default attributes and resolves the associations before taking into account associated keys manually passed in the overrides field. This lands up creating undesired entries in the DB as you'd expect it to just link to the provided foreign key, but instead it lands up linking the provided key and creating an loose hanging entry in the table as well.I feel the desired behaviour would be to merge the default attributes and overrides and only afterwards resolve the associations. We noticed this because we have unique constraints on some of our tables and tests were failing because sometimes the factory would happen to create a new entry with the same unique fields and the suite would error out.
Happy to try make a PR for the desired change if this project is still being maintained!
The text was updated successfully, but these errors were encountered: