lib/trax/model/mti/entity.rb in trax_model-0.0.5 vs lib/trax/model/mti/entity.rb in trax_model-0.0.6
- old
+ new
@@ -8,10 +8,24 @@
class_attribute :_mti_namespace
scope :records, lambda{
map(&:entity)
}
+
+ scope :fully_loaded, lambda{
+ relation = current_scope.dup
+ entity_ids = relation.pluck(:id)
+ entity_types = entity_ids.map { |id| ::Trax::Model::UUID.new(id[0..1]) }
+ .map(&:record_type)
+ .flatten
+ .compact
+ .uniq
+
+ relation_names = entity_types.map{ |type| :"#{type.name.demodulize.underscore}_entity" }
+
+ current_scope.includes(relation_names).references(relation_names)
+ }
end
def model_type
@model_type ||= uuid.record_type
end
@@ -27,24 +41,10 @@
def uuid
@uuid ||= self[:id].uuid
end
module ClassMethods
- def all
- relation = super
- entity_ids = relation.pluck(:id)
- entity_types = entity_ids.map { |id| ::Trax::Model::UUID.new(id[0..1]) }
- .map(&:record_type)
- .flatten
- .compact
- .uniq
-
- relation_names = entity_types.map{ |type| :"#{type.name.demodulize.underscore}_entity" }
-
- relation.includes(relation_names).references(relation_names)
- end
-
def mti_namespace(namespace)
_mti_namespace = (namespace.is_a?(String)) ? namespace.constantize : namespace
_mti_namespace.all.reject{|model| model.abstract_class }.each do |subclass|
key = :"#{subclass.name.demodulize.underscore}_entity"
@@ -53,10 +53,9 @@
end
def multiple_table_inheritance_namespace(namespace)
mti_namespace(namespace)
end
-
end
end
end
end
end