Open dixpac opened 2 months ago
I can do it with custom enumerator method, I'm just wondering is there a better approach you would reccomend :)
def value_history
versions_meta = log_data.versions.dup
versions_with_value_changed = versions_meta.select { |version| version.changes.has_key?("value") }
Enumerator.new { |yielder| versions_with_value_changed.each { yielder << at(version: _1.version) } }
end
Yeah, we accumulated all changes into a single changeset and apply it to the current record to build a back-in-time copy: https://github.com/palkan/logidze/blob/cc0028a3e93368e797043c190566fecae513a721/lib/logidze/model.rb#L266
Thus, using #changes
doesn't work as you wish.
We can do something like this:
def value_history
logidze_versions(reverse: true, include_self: true).select do |record|
record.log_data.find_by_version(record.log_data.version).changes.key?("value")
end
end
So, we look at the Logize version information for the current version number (log_data.version
).
I have logidze on a model. That model tracks every attribute change. I have a page that is visible to the user and on that page I want to show only versions where
value column
changed.Here is the simplified example json:
If i take enumerator approach:
Issue here is with the version 3, running
changes["value"]
on a version 3 will show changes for the value (from the v1 if I'm seeing this correctly)Basically I need to get all the records where
value changed
. How would you recommend implementing this?