-
Notifications
You must be signed in to change notification settings - Fork 69
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
has_many dupes do not set belongs_to in memory #93
Comments
I'm also seeing a similar error, which has, I believe, the same root cause. I'm using delegation, i.e.: class User
has_many :posts
end
class Post
belongs_to :user, optional: false
has_many :attachments
amoeba do
enable
end
end
class Attachment
belongs_to :attachable, polymorphic: true
delegate :user, to: :attachable
end When I try to duplicate a Using @adsteel 's proposed solution has resolved it for me! The funny thing is that this has been working correctly on rails 5.2 with Ruby 2.5. The issue has appeared after upgrading to Ruby 2.7 and Rails 6.1 |
After some digging I've found a similar issue that appears in code that is not related to amoeba at all. It looks like a bug in rails, which doesn't set the inverse association when the new record is created via |
I use class User
has_many :posts, inverse_of: :user
...
end Readme have this information, see https://github.com/amoeba-rb/amoeba#validating-nested-attributes |
Given the following models:
When I attempt to amoeba dupe a user, it will fail
This is because amoeba sets only
user.posts
in memory, but notpost.user
and the presence validator is run before anything is saved.The following fixes the issue:
The text was updated successfully, but these errors were encountered: