is_paranoid_ext 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/is_paranoid_ext.gemspec +1 -1
- data/lib/is_paranoid_ext.rb +18 -30
- metadata +2 -2
data/is_paranoid_ext.gemspec
CHANGED
data/lib/is_paranoid_ext.rb
CHANGED
@@ -1,44 +1,32 @@
|
|
1
1
|
require 'activerecord'
|
2
2
|
|
3
3
|
module IsParanoidExt
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
has_many association_id, options, &extension
|
4
|
+
|
5
|
+
def preload_has_one_association(records, reflection, preload_options = {})
|
6
|
+
super(records, reflection, paranoid_preload_options(reflection, preload_options))
|
8
7
|
end
|
9
|
-
|
10
|
-
def
|
11
|
-
|
12
|
-
has_and_belongs_to_many association_id, options, &extension
|
8
|
+
|
9
|
+
def preload_has_many_association(records, reflection, preload_options = {})
|
10
|
+
super(records, reflection, paranoid_preload_options(reflection, preload_options))
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
|
17
|
-
has_one association_id, options, &extension
|
13
|
+
def preload_has_and_belongs_to_many_association(records, reflection, preload_options = {})
|
14
|
+
super(records, reflection, paranoid_preload_options(reflection, preload_options))
|
18
15
|
end
|
19
16
|
|
20
17
|
private
|
21
|
-
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def apply_paranoid_conditions_for(association_id)
|
33
|
-
reflection = reflections[association_id.to_sym]
|
34
|
-
association_klass = ( reflection.try(:klass) || association_id.to_s.classify.constantize )
|
35
|
-
if association_klass && association_klass.respond_to?(:restore)
|
36
|
-
sql_array = ["#{association_klass.quoted_table_name}.#{association_klass.destroyed_field} IS ?"]
|
37
|
-
sql_array << association_klass.field_not_destroyed
|
38
|
-
@paranoid_conditions << sanitize_sql_array(sql_array)
|
18
|
+
|
19
|
+
def paranoid_preload_options(reflection, preload_options)
|
20
|
+
paranoid_preload_opts = preload_options.dup
|
21
|
+
if reflection.klass.respond_to?(:restore)
|
22
|
+
sql_array = ["#{reflection.klass.quoted_table_name}.#{reflection.klass.destroyed_field} IS ?"]
|
23
|
+
sql_array << reflection.klass.field_not_destroyed
|
24
|
+
preload_conditions = paranoid_preload_opts.delete(:conditions) || []
|
25
|
+
paranoid_preload_opts.merge(:conditions => merge_conditions(sql_array, preload_conditions))
|
39
26
|
end
|
27
|
+
paranoid_preload_opts
|
40
28
|
end
|
41
|
-
|
29
|
+
|
42
30
|
end
|
43
31
|
|
44
32
|
ActiveRecord::Base.send(:extend, IsParanoidExt)
|