Reputation: 7039
Im working on a project that allows users to submit and vote on changes. However I want to keep a version of the original so users can view it and see the difference between the original and what has been voted on to change. What Im wondering is what is the best way to do this?
I was originally thinking of creating the recipe twice and making a reference to one of the ids in the other as the original, but wondering if there is a more efficient way of doing this.
Upvotes: 0
Views: 50
Reputation: 5112
i think there a many ways to do it:-
Using two tables,first table will store every recipes created,other table will just store last recipe id of that user(user.recipes.last) after every new recipe is created using has many through
model.So for example:-
user has_many :recipe_copies, :dependent => :destroy user has_many :recipe through: :recipe_copies
so for every new record in recipes
table,you can ADD new row in recipes_copy
table using user.recipes.last.id
and New recipe
id and store it in copy table.
such as
recipe_copies:- previous_recipe,recipe_id,user_id
recipes:- name,user_id,description,active...etc
Hope it helps
Upvotes: 1