lib/dato/local/items_repo.rb in dato-0.3.22 vs lib/dato/local/items_repo.rb in dato-0.3.23
- old
+ new
@@ -10,19 +10,24 @@
def initialize(entities_repo)
@entities_repo = entities_repo
@collections_by_type = {}
@items_by_id = {}
+ @items_by_parent_id = {}
@item_type_methods = {}
build_cache!
end
def find(id)
@items_by_id[id.to_s]
end
+ def children_of(id)
+ @items_by_parent_id[id.to_s]
+ end
+
def respond_to_missing?(method, include_private = false)
if collections_by_type.key?(method)
true
else
super
@@ -114,9 +119,14 @@
unless item_entity.item_type.singleton
@collections_by_type[method].push item
end
@items_by_id[item.id] = item
+
+ if item_entity.respond_to?(:parent_id) && item_entity.parent_id
+ @items_by_parent_id[item_entity.parent_id] ||= []
+ @items_by_parent_id[item_entity.parent_id] << item
+ end
end
item_types.each do |item_type|
method = item_type_methods[item_type]
if !item_type.singleton && item_type.sortable