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

Association custom query #97

Open
yosiat opened this issue Mar 18, 2021 · 1 comment
Open

Association custom query #97

yosiat opened this issue Mar 18, 2021 · 1 comment

Comments

@yosiat
Copy link

yosiat commented Mar 18, 2021

Hi,

I am using ameoba for duplicating an AR with has_many association, the association is not used anywhere, only for duplication purposes.

The association is querying via not optimized field, so I want to customize the duplication logic, right now I did something like:

amoeba do
  enable

  exclude_association :comments
  customize(lambda { |old_post, new_post|
    new_post.comments = old_post.comments.where(author_id: old_post.author_id).map(&:amoeba_dup)
  })
end

Is there a better way to accomplish this? or this is the recommended solution?

@Kutomore
Copy link

I have a similar issue, but I want to dup only if a field on the child is true. Might be good to have some clarification on it since I couldn't find any querying exapmles in the docs.

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

2 participants