Module: Tenacity::OrmExt::MongoMapper::ClassMethods
- Includes:
- Helpers
- Defined in:
- lib/tenacity/orm_ext/mongo_mapper.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#_t_serialize_id_for_sql, #_t_serialize_ids, #id_class_for
Instance Method Details
#_t_delete(ids, run_callbacks = true) ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 95
def _t_delete(ids, run_callbacks=true)
if run_callbacks
destroy(_t_serialize_ids(ids))
else
delete(_t_serialize_ids(ids))
end
end
|
#_t_find(id) ⇒ Object
52
53
54
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 52
def _t_find(id)
find(_t_serialize(id))
end
|
#_t_find_all_by_associate(property, id) ⇒ Object
64
65
66
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 64
def _t_find_all_by_associate(property, id)
all(property => _t_serialize(id))
end
|
#_t_find_all_ids_by_associate(property, id) ⇒ Object
68
69
70
71
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 68
def _t_find_all_ids_by_associate(property, id)
results = collection.find({property => _t_serialize(id)}, {:fields => 'id'}).to_a
results.map { |r| r['_id'] }
end
|
#_t_find_bulk(ids = []) ⇒ Object
56
57
58
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 56
def _t_find_bulk(ids=[])
find(_t_serialize_ids(ids))
end
|
#_t_find_first_by_associate(property, id) ⇒ Object
60
61
62
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 60
def _t_find_first_by_associate(property, id)
first(property => _t_serialize(id))
end
|
#_t_id_type ⇒ Object
48
49
50
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 48
def _t_id_type
String
end
|
#_t_initialize_belongs_to_association(association) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 87
def _t_initialize_belongs_to_association(association)
unless self.respond_to?(association.foreign_key)
key association.foreign_key, id_class_for(association)
key association.polymorphic_type, String if association.polymorphic?
after_destroy { |record| record._t_cleanup_belongs_to_association(association) }
end
end
|
#_t_initialize_has_many_association(association) ⇒ Object
82
83
84
85
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 82
def _t_initialize_has_many_association(association)
after_save { |record| record.class._t_save_associates(record, association) }
before_destroy { |record| record._t_cleanup_has_many_association(association) }
end
|
#_t_initialize_has_one_association(association) ⇒ Object
78
79
80
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 78
def _t_initialize_has_one_association(association)
before_destroy { |record| record._t_cleanup_has_one_association(association) }
end
|
#_t_initialize_tenacity ⇒ Object
73
74
75
76
|
# File 'lib/tenacity/orm_ext/mongo_mapper.rb', line 73
def _t_initialize_tenacity
before_save { |record| record._t_verify_associates_exist }
after_save { |record| record._t_save_autosave_associations }
end
|