Does anybody know how to make the following code work:

invoice = Invoice.select('id, date').find(1)
invoice.conf_date = Date.today
invoice.save

As it's mentioned in guides "If the select method is used, all the
returning objects will be read only" the code below throws an
ActiveRecord::MissingAttributeError exception.


Any help will be highly appreciated!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Mar 4, 2012 at 12:38 pm

    On 4 March 2012 09:09, arturturik wrote:
    Does anybody know how to make the following code work:

    invoice = Invoice.select('id, date').find(1)
    invoice.conf_date = Date.today
    invoice.save

    As it's mentioned in guides "If the select method is used, all the
    returning objects will be read only" the code below throws an
    ActiveRecord::MissingAttributeError exception.
    There is no need for the select in the find, just do
    invoice = Invoice.find(1)
    invoice.conf_date = Date.today
    invoice.save

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Arturturik at Mar 4, 2012 at 2:38 pm
    Unfortunately, i have to use select() since the table consists of many
    BLOB columns which i prefer not to fetch.


    On Mar 4, 2:37 pm, Colin Law wrote:
    On 4 March 2012 09:09, arturturik wrote:

    Does anybody know how to make the following code work:
    invoice = Invoice.select('id, date').find(1)
    invoice.conf_date = Date.today
    invoice.save
    As it's mentioned in guides "If the select method is used, all the
    returning objects will be read only" the code below throws an
    ActiveRecord::MissingAttributeError exception.
    There is no need for the select in the find, just do
    invoice = Invoice.find(1)
    invoice.conf_date = Date.today
    invoice.save

    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Michael Pavling at Mar 4, 2012 at 2:53 pm

    On 4 March 2012 14:38, arturturik wrote:
    Unfortunately, i have to use select() since the table consists of many
    BLOB columns which i prefer not to fetch.
    But why are fetching at all? If all you're doing is changing the date
    (although I see you select "date" [1] and update "conf_date"), why not
    use .update?
    http://apidock.com/rails/ActiveRecord/Base/update/class


    [1] *Very* bad name for a column...

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Michael Pavling at Mar 4, 2012 at 2:55 pm

    On 4 March 2012 14:53, Michael Pavling wrote:
    On 4 March 2012 14:38, arturturik wrote:
    Unfortunately, i have to use select() since the table consists of many
    BLOB columns which i prefer not to fetch.
    But why are fetching at all?
    PS and if your table is arranged in such a way to prevent you from
    populating records, maybe a bit of remodelling those BLOBs out to
    associations would be in order?

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Arturturik at Mar 4, 2012 at 3:08 pm
    1. update_attribute makes no valition
    2. Column names are dummy
    3. Model.update(id, attrs) is the way worth trying.

    I just thought there is more convenient way to do that.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Arturturik at Mar 4, 2012 at 3:09 pm
    PS and if your table is arranged in such a way to prevent you from
    populating records, maybe a bit of remodelling those BLOBs out to
    associations would be in order?

    That's not an option.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Arturturik at Mar 4, 2012 at 3:10 pm
    * 1. update_attribute makes no validation

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Norm Scherer at Mar 4, 2012 at 4:18 pm

    On 03/04/2012 08:10 AM, arturturik wrote:
    * 1. update_attribute makes no validation
    But update_attributes does use validation. You can use
    update_attributes with only a single attribute.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Arturturik at Mar 4, 2012 at 4:34 pm
    Nope, i can't. It gets not saved.
    On Mar 4, 6:17 pm, Norm Scherer wrote:
    On 03/04/2012 08:10 AM, arturturik wrote:> * 1. update_attribute makes no validation

    But update_attributes does use validation.  You can use
    update_attributes with only a single attribute.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Mar 4, 2012 at 4:36 pm

    On 4 March 2012 16:34, arturturik wrote:
    Nope, i can't. It gets not saved.
    Well you are doing it wrong then.

    Colin
    On Mar 4, 6:17 pm, Norm Scherer wrote:
    On 03/04/2012 08:10 AM, arturturik wrote:> * 1. update_attribute makes no validation

    But update_attributes does use validation.  You can use
    update_attributes with only a single attribute.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Peter Vandenabeele at Mar 4, 2012 at 2:54 pm

    On Sun, Mar 4, 2012 at 3:38 PM, arturturik wrote:
    Unfortunately, i have to use select() since the table consists of many
    BLOB columns which i prefer not to fetch.
    On Mar 4, 2:37 pm, Colin Law wrote:
    On 4 March 2012 09:09, arturturik wrote:

    Does anybody know how to make the following code work:
    invoice = Invoice.select('id, date').find(1)
    invoice.conf_date = Date.today
    invoice.save
    As it's mentioned in guides "If the select method is used, all the
    returning objects will be read only" the code below throws an
    ActiveRecord::MissingAttributeError exception.
    There is no need for the select in the find, just do
    invoice = Invoice.find(1)
    invoice.conf_date = Date.today
    invoice.save
    It seems "update_attribute" could do this.

    (that is updating one field, without fetching the entire record
    with the large blobs).

    1.9.3p0 :005 > o = Order.select('uuid, name').first
    Order Load (0.8ms) SELECT uuid, name FROM "orders" ORDER BY
    orders.created_at LIMIT 1
    => #<Order uuid: "6529fb26-6b6f-402c-a9af-cba0d7f4f288", name: "...">
    1.9.3p0 :006 > o.update_attribute :name, 'test'
    (0.3ms) BEGIN
    (68.6ms) UPDATE "orders" SET "name" = 'test', "updated_at" =
    '2012-03-04 14:53:02.743113' WHERE "orders"."uuid" =
    '6529fb26-6b6f-402c-a9af-cba0d7f4f288'
    (30.1ms) COMMIT
    => true

    HTH,

    Peter

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 4, '12 at 11:57a
activeMar 4, '12 at 4:36p
posts12
users5
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase