Evan Weaver on 24 Jan 2008 11:01:34 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PhillyOnRails] ActiveRecord: updating a single attribute

  • From: "Evan Weaver" <evan@cloudbur.st>
  • To: talk@phillyonrails.org
  • Subject: Re: [PhillyOnRails] ActiveRecord: updating a single attribute
  • Date: Thu, 24 Jan 2008 14:01:21 -0500
  • Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=SvC7oeqGAmjG03WvSdSA3U1frhurbAoY6/gqpm9ji7c=; b=pthDohlZ2HoKUz7SKQmwWB/U29SLn9bBP+QeZ1CpPmJHuQN3MvQKMkX3uTI2Z0/m90rSPp/FaP4KA7Rs/HMSZ70kxVdAl2ze5xVSEOHxECKkbgTKB7aD7CFNqRmBHqg9HtRZxfMHxCmPaVI8zRUvXcjroJ28Ho5ckIOVn1w9aJc=
  • List-archive: <http://lists.phillyonrails.org/pipermail/talk>
  • Reply-to: talk@phillyonrails.org
  • Sender: talk-bounces@phillyonrails.org

Is the full update itself slow for you guys (i.e., have you
benchmarked?) Or are you trying to update a value without initially
loading the record.

Evan

On Jan 24, 2008 1:58 PM, Justin Reagor <justinwr@gmail.com> wrote:
> I was going to say the same thing... that still updates every
> column... :(
>
>
> On Jan 24, 2008, at 1:52 PM, Adam Lamar wrote:
>
> > Perhaps you could try
> > model.update_attribute_with_validation_skipping(name, value) ?
> >
> > http://api.rubyonrails.org/classes/ActiveRecord/
> > Validations.html#M001313
> >
> > Adam
> >
> > On 1/24/08, Grant Ammons <grant@fakeboard.com> wrote:
> >> Are we talking about validations on the DB or app side?
> >>
> >> If we follow DHH's opinions, validations should occur on the app
> >> side, hence
> >> rails validations.
> >>
> >> model.valid? seems like a good way of enforcing validations on the
> >> app side,
> >> thus removing the need to pass to db to validate a model.
> >>
> >> -Grant
> >>
> >>
> >> On Jan 24, 2008 11:48 AM, Evan Weaver < evan@cloudbur.st> wrote:
> >>> You can't enforce validations if you don't resave every attribute
> >>> every
> >> time.
> >>>
> >>> Evan
> >>>
> >>>
> >>> On Jan 24, 2008 12:33 PM, Chris Cera <chris@cera.us> wrote:
> >>>
> >>>
> >>>
> >>>> Hi everyone,
> >>>>
> >>>> Is there a way to update just one attribute of a record without
> >>>> causing all the attributes to be re-set?  When I use the
> >>>> update_attribute() or increment(), since they call save() it
> >>>> causes every attribute to get re-set.  I verified this in the
> >>>> mysql 'General Query Log'.  Example:
> >>>>     item.update_attribute(:normal_views, item.normal_views + 1)
> >>>>
> >>>> I feel that there must be a more elegant solution than this:
> >>>>     sql = 'UPDATE documents SET normal_views = normal_views + 1
> >>>> WHERE id
> >> = ' + item.id.to_s
> >>>>     ActiveRecord::Base.connection.update(sql)
> >>>>
> >>>> Any suggestions are greatly appreciated.  Thank you, -Chris
> >>>>
> >>>> ref:
> >> http://api.rubyonrails.org/classes/ActiveRecord/Base.html
> >>>>
> >>>> --
> >>>> Christopher D. Cera
> >>>> CTO, Hovitate LLC
> >>>> http://vuzit.com
> >>>> P: 215.435.2289
> >>>> F: 267.295.7369
> >>>> _______________________________________________
> >>>> To unsubscribe or change your settings, visit:
> >>>> http://lists.phillyonrails.org/mailman/listinfo/talk
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Evan Weaver
> >>> Cloudburst, LLC
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> To unsubscribe or change your settings, visit:
> >>> http://lists.phillyonrails.org/mailman/listinfo/talk
> >>>
> >>
> >>
> >> _______________________________________________
> >> To unsubscribe or change your settings, visit:
> >> http://lists.phillyonrails.org/mailman/listinfo/talk
> >>
> >>
> > _______________________________________________
> > To unsubscribe or change your settings, visit:
> > http://lists.phillyonrails.org/mailman/listinfo/talk
>
> _______________________________________________
> To unsubscribe or change your settings, visit:
> http://lists.phillyonrails.org/mailman/listinfo/talk
>



-- 
Evan Weaver
Cloudburst, LLC
_______________________________________________
To unsubscribe or change your settings, visit:
http://lists.phillyonrails.org/mailman/listinfo/talk