has_many_by_status 1.0.3 → 1.0.4

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 +12 -0
  2. metadata +4 -4
@@ -31,6 +31,11 @@ module ActiveRecord #:nodoc:
31
31
  end
32
32
  status_class_name = h_options[:status_class_name] || "Status"
33
33
  h_options.delete(:status_class_name)
34
+ has_destroy = false
35
+ if h_options.has_key? :dependent
36
+ has_destroy = true
37
+ h_options.delete(:dependent)
38
+ end
34
39
  #puts "!!!!!!!status_class_name = #{status_class_name}"
35
40
 
36
41
  class_eval do
@@ -41,6 +46,13 @@ module ActiveRecord #:nodoc:
41
46
  has_many "#{association_id}".to_sym, h_options.merge({:conditions => ["status_id = ?", eval("#{status_class_name}.active.id")]})
42
47
  # build default has_many ALL
43
48
  has_many "all_#{association_id}".to_sym, h_options
49
+
50
+ if has_destroy
51
+ define_method("destroy_all_#{association_id}") do
52
+ eval "self.all_#{association_id}.destroy_all"
53
+ end
54
+ before_destroy "destroy_all_#{association_id}".to_sym
55
+ end
44
56
 
45
57
  # build has_many for each status
46
58
  #puts "let's get the status' from the db..."
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.3
7
- date: 2007-03-19 00:00:00 -04:00
6
+ version: 1.0.4
7
+ date: 2007-03-22 00:00:00 -04:00
8
8
  summary: has_many_by_status
9
9
  require_paths:
10
10
  - lib
@@ -62,7 +62,7 @@ dependencies:
62
62
  version_requirement:
63
63
  version_requirements: !ruby/object:Gem::Version::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - ">"
66
66
  - !ruby/object:Gem::Version
67
- version: 1.0.2
67
+ version: 0.0.0
68
68
  version: