Skip to content

Commit

Permalink
[#777] handle new records and nils correctly in belongs_to test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
al2o3cr committed Sep 21, 2011
1 parent 23893f5 commit abb2120
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hobo/lib/hobo/model.rb
Expand Up @@ -203,9 +203,13 @@ def #{name}_changed?
end
}
else
id_method = refl.options[:primary_key] || refl.klass.primary_key
class_eval %{
def #{name}_is?(target)
target.class <= ::#{refl.klass.name} && target.#{id_method} == self.#{refl.primary_key_name}
our_id = self.#{refl.primary_key_name}
# if our_id is nil, only return true if target is nil
return target.nil? unless our_id
target.class <= ::#{refl.klass.name} && target.#{id_method} == our_id
end
def #{name}_changed?
#{refl.primary_key_name}_changed?
Expand Down

0 comments on commit abb2120

Please sign in to comment.