Skip to content

Commit

Permalink
Base#update_attribute isnt subject to validation
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@210 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Dec 18, 2004
1 parent 3bef4c2 commit d678997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
Now:
person.update_attributes(@params["person"])

* Added a return value for Base#update_attribute, so that you get to know whether the save was successful or if it failed validation.

* Added Base.destroy and Base.delete to remove records without holding a reference to them first.


Expand Down
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,15 @@ def clone
end

# Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records.
# Note: This method is overwritten by the Validation module that'll make sure that updates made with this method
# doesn't get subjected to validation checks. Hence, attributes can be updated even if the full object isn't valid.
def update_attribute(name, value)
self[name] = value
return save
return true
end

# Updates all the attributes in from the passed hash and saves the record.
# Updates all the attributes in from the passed hash and saves the record. If the object is invalid, the saving will
# fail and false will be returned.
def update_attributes(attributes)
self.attributes = attributes
return save
Expand Down

0 comments on commit d678997

Please sign in to comment.