Sha256: 168b88c7f23bea284c4776b14eef6ce30a59c40a6ca296c9f4ec7199a9621935
Contents?: true
Size: 1.19 KB
Versions: 123
Compression:
Stored size: 1.19 KB
Contents
class Marty::Relation # Given a Mcfly class (klass) and a list of classes which can # reference klass, returns instaces of klass which have no references. def self.not_referenced(klass, ref_classes) col = (klass.name.split('::').last.snakecase + "_id").to_sym ids = klass.where(obsoleted_dt: 'infinity').pluck(:group_id) ref_ids = ref_classes.map { |rclass| rclass.where(obsoleted_dt: 'infinity', col => ids).pluck(col) }.flatten.uniq klass.where(id: ids - ref_ids).to_a end # Find Mcfly references from klass instances which have been # obsoleted. A hash is returned with a key for each # mcfly_belongs_to reference from klass. def self.obsoleted_references(klass) assoc_h = Marty::DataConversion.associations(klass) assoc_h.each_with_object({}) do |(a, ah), h| assoc_class = ah[:assoc_class] foreign_key = ah[:foreign_key] next unless Mcfly.has_mcfly? assoc_class h[a] = klass.where(obsoleted_dt: 'infinity').map do |obj| ref_key = obj.send(foreign_key) next unless ref_key ref = assoc_class.find(ref_key) obj unless Mcfly.is_infinity(ref.obsoleted_dt) end.compact end end end
Version data entries
123 entries across 123 versions & 1 rubygems