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
ensure_index :account_id
ensure_index :space_id
end
|