mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
Story#115762063 - all contacts are using the same versions logic
This commit is contained in:
parent
779a47c80f
commit
028aa31232
2 changed files with 24 additions and 7 deletions
|
@ -55,4 +55,22 @@ module Versions
|
|||
domains.each(&:touch_with_version)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def all_versions_for(ids, time)
|
||||
ver_klass = paper_trail_version_class
|
||||
from_history = ver_klass.where(item_id: ids).
|
||||
order(:item_id).
|
||||
preceding(time + 1, true).
|
||||
select("distinct on (item_id) #{ver_klass.table_name}.*").
|
||||
map do |ver|
|
||||
o = new(ver.object)
|
||||
ver.object_changes.to_h.each { |k, v| o[k]=v[-1] }
|
||||
o
|
||||
end
|
||||
not_in_history = where(id: (ids - from_history.map(&:id)))
|
||||
|
||||
from_history + not_in_history
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue