The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
What's New in Edge Rails: Partial Updates

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rwdaigle

Posts: 312
Nickname: rwdaigle
Registered: Feb, 2003

Ryan is a passionate ruby developer with a strong Java background.
What's New in Edge Rails: Partial Updates Posted: Apr 1, 2008 1:22 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rwdaigle.
Original Post: What's New in Edge Rails: Partial Updates
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps

Advertisement

In lock-step with the recent dirty objects functionality comes the ability of ActiveRecord models to perform partial updates – which only saves the attributes that have been modified on updates.

For instance:

1
2
3
4
5
6
7
8
9
10
article = Article.find(:first)
article.title  #=> "Title"
article.subject  #=> "Edge Rails"

# Update one of the attributes
article.title = "New Title"

# And only that updated attribute is persisted to the db
article.save
  #=>  "UPDATE articles SET title = 'New Title' WHERE id = 1"

Note: Your updated_at/on magic fields will only be set if there are unsaved attributes that need persisting. If there are no changed attributes for the object being persisted then there won’t be any SQL updates made.

To enable this functionality, set partial_updates = true for each model you wish to take advantage of partial updates. To enable this system-wide add this line to your environment.rb or, better yet, in a config/initializer:


ActiveRecord::Base.partial_updates = true

Note: There’s currently a config/initializers/new_rails_defaults.rb file that has this setting, so edit that file if you have it.

tags: ruby, rubyonrails

Read: What's New in Edge Rails: Partial Updates

Topic: Disk-Based Parallel Computation Previous Topic   Next Topic Topic: MountainWest Ramazers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use