Module: MongoMapper::Plugins::Multitenant::ClassMethods

Defined in:
lib/rad/mongo_mapper/multitenant.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_space!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rad/mongo_mapper/multitenant.rb', line 10

def belongs_to_space!
  keys.symbolize_keys.must_not.include :account_id
  
  key :account_id, ObjectId, :default => lambda{Account.current? ? Account.current.id : nil}, :protected => true
  belongs_to :account

  key :space_id, ObjectId, :default => lambda{Space.current? ? Space.current.id : nil}, :protected => true
  belongs_to :space    

  validates_presence_of :account_id, :space_id

  default_scope do 
    Space.current? ? {:space_id => Space.current.id} : {}
  end
  
  # defer do
  ensure_index :account_id
  ensure_index :space_id
  # end
end

#connect_to_global_databaseObject



6
7
8
# File 'lib/rad/mongo_mapper/multitenant.rb', line 6

def connect_to_global_database      
  use_database :global
end