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

Setting only clone puts amoeba in indiscriminate mode #82

Open
benjamin-hull opened this issue Jan 22, 2019 · 0 comments
Open

Setting only clone puts amoeba in indiscriminate mode #82

benjamin-hull opened this issue Jan 22, 2019 · 0 comments

Comments

@benjamin-hull
Copy link

This is a sub-issue or related to #75. If you have a clone declaration but set neither include or exclude on a model, amoeba is set to indiscriminate/copy everything mode, as both amoeba.includes and amoeba.excludes is empty.

A fix which I'm using ensures the cloned column is also present in the includes in this case. Seems to work for my use case:

def apply_clones
  amoeba.clones.each do |clone_field|
    ensure_clone_in_includes(clone_field)
    exclude_clone_if_has_many_through(clone_field)
  end
end

# If the field to be cloned isn't in the includes, add it so it 
# can be processed in the apply_associations step.
# This handles the case where no includes or excludes are set.
def ensure_clone_in_includes(clone_field)
  return if amoeba.excludes.present?
  amoeba.includes[clone_field] = {} unless amoeba.includes.values.include?(clone_field)
end

Happy to place a PR with this change if someone wouldn't mind reviewing it.

@benjamin-hull benjamin-hull changed the title Setting only clone puts amoeba in an indiscriminate mode Setting only clone puts amoeba in indiscriminate mode Jan 22, 2019
@benjamin-hull benjamin-hull changed the title Setting only clone puts amoeba in indiscriminate mode Setting only clone puts amoeba in indiscriminate mode Jan 22, 2019
benjamin-hull added a commit to companionstudio/amoeba that referenced this issue Jan 22, 2019
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