Permalink
Browse files

additional scopes for member and resource network

  • Loading branch information...
1 parent 2d98f44 commit e639ee73690a30d88b915ca7d64f39ccc65f0aef @nebojsaz nebojsaz committed Apr 7, 2012
Showing with 7 additions and 0 deletions.
  1. +1 −0 app/models/human_network/member.rb
  2. +6 −0 app/models/resource_network.rb
@@ -1,4 +1,5 @@
class Member < HumanNetwork
scope :village_members, lambda { |village| where("entity_id = ? AND entity_type = ?", village.id, "Village")}
+ scope :person_villages, lambda { |person| where("person_id = ? AND entity_type = ?", person.id, "Village")}
end
@@ -16,6 +16,7 @@ class ResourceNetwork < ActiveRecord::Base
scope :only_items, where(:resource_type_id => EntityType::ITEM_ENTITY)
scope :entity, lambda { |entity| where("entity_id =? AND entity_type_id = ?", entity.id, EntityType::PERSON_ENTITY) }
scope :entity_items, lambda { |entity| where("entity_id =? AND entity_type_id = ? AND resource_type_id =?", entity.id, EntityType::PERSON_ENTITY, EntityType::ITEM_ENTITY) }
+ scope :group_items, lambda { |entity| where("entity_id =? AND entity_type_id = ? AND resource_type_id =?", entity.id, EntityType::ENTITY_TYPES.invert[entity.class.name], EntityType::ITEM_ENTITY) }
scope :village_resources, lambda { |village_id | where("entity_id =? AND entity_type_id = ?", village_id, EntityType::VILLAGE_ENTITY)}
scope :items, lambda { |items| where("resource_type_id=? AND resource_id in (?)", EntityType::ITEM_ENTITY, items)}
scope :gifter, :conditions => { :type => TYPE_GIFTER }
@@ -49,4 +50,9 @@ def to_gifter_and_possessor!
self.type = TYPE_GIFTER_AND_POSSESSOR
save!
end
+
+ def self.items_belong_to(entity)
+ resource_ids = self.group_items(entity).map(&:resource_id)
+ Item.find_all_by_id(resource_ids)
+ end
end

0 comments on commit e639ee7

Please sign in to comment.