Skip to content

Commit

Permalink
id_in_database do not return nil value for persisted record
Browse files Browse the repository at this point in the history
This removes `|| id` which were added in rails#9963 and rails#23887 since it is no
longer necessary.
  • Loading branch information
kamipo committed Mar 5, 2018
1 parent 4a46ba9 commit aa2b1ab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def _update_record(attribute_names = self.attribute_names)
rows_affected = 0
@_trigger_update_callback = true
else
rows_affected = self.class.unscoped._update_record attributes_values, id, id_in_database
rows_affected = self.class.unscoped._update_record(attributes_values, id_in_database)
@_trigger_update_callback = rows_affected > 0
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def insert(values) # :nodoc:
binds)
end

def _update_record(values, id, id_was) # :nodoc:
def _update_record(values, id) # :nodoc:
substitutes, binds = substitute_values values

scope = @klass.unscoped
Expand All @@ -76,7 +76,7 @@ def _update_record(values, id, id_was) # :nodoc:
scope.unscope!(where: @klass.inheritance_column)
end

relation = scope.where(@klass.primary_key => (id_was || id))
relation = scope.where(@klass.primary_key => id)
bvs = binds + relation.bound_attributes
um = relation
.arel
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations/uniqueness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def validate_each(record, attribute, value)
relation = build_relation(finder_class, attribute, value)
if record.persisted?
if finder_class.primary_key
relation = relation.where.not(finder_class.primary_key => record.id_in_database || record.id)
relation = relation.where.not(finder_class.primary_key => record.id_in_database)
else
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
end
Expand Down

0 comments on commit aa2b1ab

Please sign in to comment.