Module: Tenacity::OrmExt::ActiveRecord::ClassMethods
- Includes:
- Helpers
- Defined in:
- lib/tenacity/orm_ext/activerecord.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
98
99
100
101
102
103
104
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 98
def _t_delete(ids, run_callbacks=true)
if run_callbacks
destroy_all(["id in (?)", _t_serialize_ids(ids)])
else
delete_all(["id in (?)", _t_serialize_ids(ids)])
end
end
|
#_t_find(id) ⇒ Object
59
60
61
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 59
def _t_find(id)
find_by_id(_t_serialize(id))
end
|
#_t_find_all_by_associate(property, id) ⇒ Object
72
73
74
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 72
def _t_find_all_by_associate(property, id)
find(:all, :conditions => ["#{property} = ?", _t_serialize(id)])
end
|
#_t_find_all_ids_by_associate(property, id) ⇒ Object
76
77
78
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 76
def _t_find_all_ids_by_associate(property, id)
connection.select_values("SELECT id FROM #{table_name} WHERE #{property} = #{_t_serialize_id_for_sql(id)}")
end
|
#_t_find_bulk(ids) ⇒ Object
63
64
65
66
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 63
def _t_find_bulk(ids)
return [] if ids.nil? || ids.empty?
find(:all, :conditions => ["id in (?)", _t_serialize_ids(ids)])
end
|
#_t_find_first_by_associate(property, id) ⇒ Object
68
69
70
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 68
def _t_find_first_by_associate(property, id)
find(:first, :conditions => ["#{property} = ?", _t_serialize(id)])
end
|
#_t_id_type ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 51
def _t_id_type
@_t_id_type_clazz ||= begin
Kernel.const_get(columns.find{ |x| x.primary }.type.to_s.capitalize)
rescue
Integer
end
end
|
#_t_initialize_belongs_to_association(association) ⇒ Object
94
95
96
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 94
def _t_initialize_belongs_to_association(association)
after_destroy { |record| record._t_cleanup_belongs_to_association(association) }
end
|
#_t_initialize_has_many_association(association) ⇒ Object
89
90
91
92
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 89
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
80
81
82
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 80
def _t_initialize_has_one_association(association)
before_destroy { |record| record._t_cleanup_has_one_association(association) }
end
|
#_t_initialize_tenacity ⇒ Object
84
85
86
87
|
# File 'lib/tenacity/orm_ext/activerecord.rb', line 84
def _t_initialize_tenacity
before_save { |record| record._t_verify_associates_exist }
after_save { |record| record._t_save_autosave_associations }
end
|