johnsbrn-classy-inheritance 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/lib/classy-inheritance.rb +32 -1
- data/test/test_helper.rb +1 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
== 0.6.5 2009-02-01
|
2
|
+
* Add fix for has_one primary key bug - http://rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug
|
1
3
|
== 0.6.4 2009-02-01
|
2
4
|
* Updated deprecated default error messages - johnsbrn
|
3
5
|
* Added has_dependency for non-polymorphic has_one - johnsbrn
|
data/lib/classy-inheritance.rb
CHANGED
@@ -1,12 +1,43 @@
|
|
1
1
|
module Stonean
|
2
2
|
module ClassyInheritance
|
3
|
-
VERSION = '0.6.
|
3
|
+
VERSION = '0.6.5'
|
4
4
|
|
5
5
|
def self.version
|
6
6
|
VERSION
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
+
|
11
|
+
# fix active record has_one primary key bug - http://rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug
|
12
|
+
def has_one(association_id, options = {})
|
13
|
+
if options[:through]
|
14
|
+
reflection = create_has_one_through_reflection(association_id, options)
|
15
|
+
association_accessor_methods(reflection, ActiveRecord::Associations::HasOneThroughAssociation)
|
16
|
+
else
|
17
|
+
reflection = create_has_one_reflection(association_id, options)
|
18
|
+
|
19
|
+
ivar = "@#{reflection.name}"
|
20
|
+
|
21
|
+
method_name = "has_one_after_save_for_#{reflection.name}".to_sym
|
22
|
+
define_method(method_name) do
|
23
|
+
association = instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
24
|
+
if !association.nil? && (new_record? || association.new_record? || association[reflection.primary_key_name] != id)
|
25
|
+
primary_key = reflection.options[:primary_key] || :id
|
26
|
+
association[reflection.primary_key_name] = send(primary_key)
|
27
|
+
association.save(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
after_save method_name
|
31
|
+
|
32
|
+
add_single_associated_validation_callbacks(reflection.name) if options[:validate] == true
|
33
|
+
association_accessor_methods(reflection, ActiveRecord::Associations::HasOneAssociation)
|
34
|
+
association_constructor_method(:build, reflection, ActiveRecord::Associations::HasOneAssociation)
|
35
|
+
association_constructor_method(:create, reflection, ActiveRecord::Associations::HasOneAssociation)
|
36
|
+
|
37
|
+
configure_dependency_for_has_one(reflection)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
10
41
|
def depends_on(model_sym, options = {})
|
11
42
|
define_relationship(model_sym,options)
|
12
43
|
|
data/test/test_helper.rb
CHANGED