-
Notifications
You must be signed in to change notification settings - Fork 74
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
How to turn on Associations versioning #45
Comments
Any update to this, was trying to switch from papertrail and would like to get this started |
@Adeering Hi! You can create a file |
Ok so I created the file and turned it on, but it doesnt seem to be working. Both models have the has_logidze and independently they log the changes. I have a recipe table and a recipe_ingredient table. The recipe has_many recipe_ingredients. When I update a recipe_ingredient it saves the update in the log, but the log count in the recipe log_data doesnt change |
@Adeering can you please provide actual code, that you running? With the notes, what results are you expecting, and what you actually get |
Sure here is the code:
Recipe Ingredients Model:
And then my recipes controller:
Lastly the logidze.rb in the initializers: So I might be misunderstanding what is going to happen with the associated records, but expecting it to create a new version in the recipe log_data column whenever an ingredient changes. Right now it saves a new version of the ingredient in the ingredients log_data column but nothing changes in the recipe log_data column. What im trying to do is create a view so the user can cycle thru all the changes and see what has changed. To do that I need to have a base reference as to which changes to call out for a set of changes, so was thinking that would be put in the recipes log_data column |
@Adeering I am afraid, it's not, how it works. When you change ingredients, no new |
Ok, so if the only things that are changing are the ingredients, is there a way I could cycle thru and show each time there is a change? More than just 1 ingredient can change at a time also |
I guess, there is no 100% reliable way to do that. You can do something like this, of course:
But this approach doesn't take into account deleted ingredients, the won't be shown @palkan maybe, you've got some ideas here? Am I missing something? |
I have the following idea: # Custom enumerator
recipe.each_version(includes: :recipe_ingredients) do |(timestamp, recipe_at_the_time)|
# here recipe_at_the_time is just recipe.at(timestamp)
end
# To solve the problem of multiple changes within a short amount of time,
# we can provide a threshold option: combine changes which are less 1 minute one from each other.
recipe.each_version(include: :recipe_ingredients, threshold: 1.minute) do
...
end Logidze doesn't have a special support for deleted association records. But you can combine it with class Recipe < ApplicationRecord
acts_as_paranoid
# add another association that takes into account deleted records
has_many :recipe_ingridients_with_deleted, -> { with_deleted }
end
# and then
recipe.each_version(include: :recipe_ingredients_with_deleted) do
...
end @Adeering What do you think about the idea? Does it solve your problem? |
Ok, so I think I figured out a way to do this. So in my case Im not trying to track a normal edit from a user. What happens is users vote on changes to recipes and if they get enough votes they get applied and change the recipe. I already track how many changes get approved for my search functions....originally I blacklisted all my counter indexes, but I can whitelist the successful change count and that will trigger a version in the recipe to be created. Then use the enumerator you suggested to display them. So new question...how can I go back and change the whitelist? |
Just released v0.5.3 which add support for upgrade migrations (see #46). Just run generator with rails generate logidze:model recipe --update --whitelist=... And run
Just to clarify: the enumerator above is just a proposal, it's not there yet) If you would like to implement it – feel free to submit a PR) |
ok, should be simple enough to create a loop, since you can reference each version via the version number. I think I've got a solid picture of what I need to do now. Thank you for the help |
Glad to help you) Closing the issue. |
So I saw in the wiki that association versioning is available and I need that feature. It has in there this:
Where do I turn on the associations_versioning setting and set it to true?
The text was updated successfully, but these errors were encountered: