app/models/cavy/item_group.rb in cavy-0.1.0.beta1 vs app/models/cavy/item_group.rb in cavy-0.1.0.beta2
- old
+ new
@@ -14,9 +14,19 @@
def items
Cavy::Item.where(item_group_id: id)
end
+ def items_json
+ all_items = {}
+ items.each do |item|
+ item_json = {}
+ item.data.try(:each) { |key, value| item_json[key] = value }
+ all_items[item.id] = item_json
+ end
+ all_items.to_json
+ end
+
def items_with_key_value(key, value)
item_group = Cavy::ItemGroup.find(id)
item_group.items.where("data.#{key}" => value)
end