Git Product home page Git Product logo

Comments (3)

qnsi avatar qnsi commented on August 28, 2024

Hey did you figure out something in this matter?
I have similar problem, I have two models with has_many relationship. (X and Y for example)
Sometimes X may have multiple Y, but sometimes I validate that it has only one Y.

Now when I try to clone X with just one Y (and validations for this), Y is copied first, and it can't be saved (because now X has two Ys).

Would be cool to hear about possible workarounds.

from amoeba.

cheeseandpepper avatar cheeseandpepper commented on August 28, 2024

I can't recall the exact workaround, but if I remember correctly, I played around with the various callbacks such as before_save, before_commit, after_save, after_commit etc. I believe some combination of this between the two models made it work. Good luck!

from amoeba.

ethagnawl avatar ethagnawl commented on August 28, 2024

Is the expected behavior to create the duplicated associations before the object you call amoeba_dup on? And if all of this is true, is there a way to coerce the duplication order?

I've hit upon these two questions, too.

I have an association whose duplicated object needs to access a "customized" value on its duplicated parent, however this doesn't seem to be possible -- by default. Is there any way to invert the order of the duplications? Is there a known workaround for doing this sort of thing?

UPDATE:
I was unable to find a solution using amoeba, but I solved my problem by adding columns to the parent (duplicate and duplicate_source_id) and setting those using the customize macro. I then used those columns in an after_create callback on the child model in order to access the attributes on the source model.

from amoeba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.