has_many_by_status 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/has_many_by_status.rb +7 -3
  2. metadata +2 -2
@@ -18,7 +18,10 @@ module ActiveRecord #:nodoc:
18
18
  self_class_name = self.to_s.downcase
19
19
 
20
20
  send :include, ActiveRecord::Has::ManyByStatus::ActMethods
21
+
21
22
 
23
+ status_column_name = :status_id
24
+ status_column_name = (options[:status_column_name] || :status_id).to_sym if options.is_a?(Hash)
22
25
  # check to make sure if the user has overridden the class_name field in the model.
23
26
  # if they haven't then get it from the association_id.
24
27
  unless options.has_key? :class_name
@@ -31,6 +34,7 @@ module ActiveRecord #:nodoc:
31
34
  end
32
35
  status_class_name = h_options[:status_class_name] || "Status"
33
36
  h_options.delete(:status_class_name)
37
+ h_options.delete(:status_column_name)
34
38
  has_destroy = false
35
39
  if h_options.has_key? :dependent
36
40
  has_destroy = true
@@ -43,7 +47,7 @@ module ActiveRecord #:nodoc:
43
47
  # build default has_many as active
44
48
  #puts "association_id = #{association_id}"
45
49
  #puts "h_options = #{h_options.inspect}"
46
- has_many "#{association_id}".to_sym, h_options.merge({:conditions => ["status_id = ?", eval("#{status_class_name}.active.id")]})
50
+ has_many "#{association_id}".to_sym, h_options.merge({:conditions => ["#{status_column_name} = ?", eval("#{status_class_name}.active.id")]})
47
51
  # build default has_many ALL
48
52
  has_many "all_#{association_id}".to_sym, h_options
49
53
 
@@ -60,7 +64,7 @@ module ActiveRecord #:nodoc:
60
64
  #puts "rows.size = #{rows.size}"
61
65
  rows.each do |status| #get all the statuses in the db.
62
66
  unless STATUS_EXCLUDES.include?(status.name) # don't build a deleted method
63
- has_many "#{status.name}_#{association_id}".to_sym, h_options.merge({:conditions => ["status_id = ?", status.id]})
67
+ has_many "#{status.name}_#{association_id}".to_sym, h_options.merge({:conditions => ["#{status_column_name} = ?", status.id]})
64
68
  end
65
69
  end
66
70
  end
@@ -71,7 +75,7 @@ module ActiveRecord #:nodoc:
71
75
  x_options = options
72
76
  x_options.delete(:dependent)
73
77
  define_method("deleted_#{association_id}") do
74
- eval("#{class_name}.find_with_deleted(:all, x_options.merge({:conditions => [\"#{self_class_name}_id = ? and status_id = ?\", self.id, Status.deleted.id]}))")
78
+ eval("#{class_name}.find_with_deleted(:all, x_options.merge({:conditions => [\"#{self_class_name}_id = ? and #{status_column_name} = ?\", self.id, #{status_class_name}.deleted.id]}))")
75
79
  end
76
80
 
77
81
  define_method("all_#{association_id}_with_deleted") do
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: has_many_by_status
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.4
7
- date: 2007-03-22 00:00:00 -04:00
6
+ version: 1.0.5
7
+ date: 2007-04-06 00:00:00 -04:00
8
8
  summary: has_many_by_status
9
9
  require_paths:
10
10
  - lib