moiristo / deep_cloneable

This gem gives every ActiveRecord::Base object the possibility to do a deep clone that includes user specified associations.
MIT License
785 stars 89 forks source link

has_many relationship doesn't clone #75

Closed adiakritos closed 7 years ago

adiakritos commented 7 years ago

Hello!

Here's my code:

@original_meal = Meal.find(params[:id]) @meal = @original_meal.deep_clone include: :meal_foods

This is fired off in a 'clone' action in a controller.

The meal has_many meal_foods. Each meal_foods belongs_to a meal. The meal that is being cloned has many meal_foods associated with it.

When I clone it, I do in fact see some foods in the controller before the new meal is saved, but the associations aren't saved. I see the meal itself has no id since it hasn't been saved yet, thus the meal_foods can't be associated to it.

With that said, must I clone the original meal, and then write my own code to save the meal_foods from the original meal to the new one, or is something that should be handled by this gem?

adiakritos commented 7 years ago

It was an issue with my model, nothing to do with the gem.

moiristo commented 7 years ago

Ok, thanks for the feedback :)