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

How can I "move" has_many association instead of copy? #96

Open
benlieb opened this issue Feb 2, 2021 · 0 comments
Open

How can I "move" has_many association instead of copy? #96

benlieb opened this issue Feb 2, 2021 · 0 comments

Comments

@benlieb
Copy link

benlieb commented Feb 2, 2021

It seems this functionality is not baked in, but I just want to confirm before I roll my own solution.

To clarify, I'm wanting to move the associations from the old object to the new, not duplicate them.

My hand-rolled solution is this:

  amoeba do
    # include_association :transactions (duplicates)
    # include_association :payments (duplicates)
    customize(lambda { |orig, new|
      orig.transactions.each { |t| t.invoice = new && t.save!}
      orig.payments.each     { |p| p.invoice = new && p.save!}
    })

Is there a better way?

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