Permalink
Browse files

Ensure foreign keys are set regardless of binding state. Closes #1778.

  • Loading branch information...
1 parent fc25a6d commit d2975014207faa1f99d939e87e64cd6e4cf6a1b5 @durran durran committed Apr 24, 2012
View
@@ -33,6 +33,8 @@ For instructions on upgrading to newer versions, visit
* \#1916/\#1913 Uniqueness validation no longer is affected by the default
scope. (Hans Hasselberg)
+* \#1778 Ensure foreign keys are always set regardless of binding state.
+
## 2.4.8
### Resolved Issues
@@ -19,13 +19,13 @@ class In < Binding
#
# @since 2.0.0.rc.1
def bind
+ base.you_must(metadata.foreign_key_setter, target.id)
+ if metadata.inverse_type
+ base.you_must(metadata.inverse_type_setter, target.class.model_name)
+ end
unless _binding?
_binding do
inverse = metadata.inverse(target)
- base.you_must(metadata.foreign_key_setter, target.id)
- if metadata.inverse_type
- base.you_must(metadata.inverse_type_setter, target.class.model_name)
- end
if inverse
if set_base_metadata
if base.referenced_many?
@@ -49,13 +49,13 @@ def bind
#
# @since 2.0.0.rc.1
def unbind
+ base.you_must(metadata.foreign_key_setter, nil)
+ if metadata.inverse_type
+ base.you_must(metadata.inverse_type_setter, nil)
+ end
unless _binding?
_binding do
inverse = metadata.inverse(target)
- base.you_must(metadata.foreign_key_setter, nil)
- if metadata.inverse_type
- base.you_must(metadata.inverse_type_setter, nil)
- end
if inverse
set_base_metadata
if base.referenced_many?
@@ -17,12 +17,12 @@ class Many < Binding
#
# @since 2.0.0.rc.1
def bind_one(doc)
+ doc.you_must(metadata.foreign_key_setter, base.id)
+ if metadata.type
+ doc.you_must(metadata.type_setter, base.class.model_name)
+ end
unless _binding?
_binding do
- doc.you_must(metadata.foreign_key_setter, base.id)
- if metadata.type
- doc.you_must(metadata.type_setter, base.class.model_name)
- end
doc.send(metadata.inverse_setter, base)
end
end
@@ -37,12 +37,12 @@ def bind_one(doc)
#
# @since 2.0.0.rc.1
def unbind_one(doc)
+ doc.you_must(metadata.foreign_key_setter, nil)
+ if metadata.type
+ doc.you_must(metadata.type_setter, nil)
+ end
unless _binding?
_binding do
- doc.you_must(metadata.foreign_key_setter, nil)
- if metadata.type
- doc.you_must(metadata.type_setter, nil)
- end
doc.send(metadata.inverse_setter, nil)
end
end
@@ -19,13 +19,13 @@ class One < Binding
#
# @since 2.0.0.rc.1
def bind
+ target.you_must(metadata.foreign_key_setter, base.id)
+ if metadata.type
+ target.you_must(metadata.type_setter, base.class.model_name)
+ end
unless _binding?
_binding do
- target.you_must(metadata.foreign_key_setter, base.id)
target.send(metadata.inverse_setter, base)
- if metadata.type
- target.you_must(metadata.type_setter, base.class.model_name)
- end
end
end
end
@@ -40,13 +40,13 @@ def bind
#
# @since 2.0.0.rc.1
def unbind
+ target.you_must(metadata.foreign_key_setter, nil)
+ if metadata.type
+ target.you_must(metadata.type_setter, nil)
+ end
unless _binding?
_binding do
- target.you_must(metadata.foreign_key_setter, nil)
target.send(metadata.inverse_setter, nil)
- if metadata.type
- target.you_must(metadata.type_setter, nil)
- end
end
end
end

0 comments on commit d297501

Please sign in to comment.