diff options
author | kennyj <kennyj@gmail.com> | 2012-04-12 20:33:06 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-04-13 02:25:13 +0900 |
commit | 0f3901e9101837eaab2daba5b01f67ed7e2c75d5 (patch) | |
tree | 594d2c39acbc787133c05ee67400a9b704cce7e9 | |
parent | 8248f4202d67a781bd3da88fc9412bc7264bbb7b (diff) | |
download | rails-0f3901e9101837eaab2daba5b01f67ed7e2c75d5.tar.gz rails-0f3901e9101837eaab2daba5b01f67ed7e2c75d5.tar.bz2 rails-0f3901e9101837eaab2daba5b01f67ed7e2c75d5.zip |
@stale_state should be nil when a model isn't saved.
3 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 81c6e400d2..ddfc6f6c05 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -77,7 +77,7 @@ module ActiveRecord end def stale_state - owner[reflection.foreign_key].to_s + owner[reflection.foreign_key] && owner[reflection.foreign_key].to_s end end end diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb index 2ee5dbbd70..88ce03a3cd 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -27,7 +27,8 @@ module ActiveRecord end def stale_state - [super, owner[reflection.foreign_type].to_s] + foreign_key = super + foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s] end end end diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index fd0e90aaf0..be890e5767 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -62,7 +62,7 @@ module ActiveRecord # properly support stale-checking for nested associations. def stale_state if through_reflection.macro == :belongs_to - owner[through_reflection.foreign_key].to_s + owner[through_reflection.foreign_key] && owner[through_reflection.foreign_key].to_s end end |