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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 4 March 2012 09:09, arturturik <artur-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 4 March 2012 09:09, arturturik <ar...-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 4 March 2012 14:38, arturturik <artur-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Mar 4, 2012 at 3:38 PM, arturturik <artur-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 4 March 2012 09:09, arturturik <ar...-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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.saveIt 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 4 March 2012 14:53, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 March 2012 14:38, arturturik <artur-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
* 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nope, i can''t. It gets not saved. On Mar 4, 6:17 pm, Norm Scherer <normsche...-ihVZJaRskl1bRRN4PJnoQQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 4 March 2012 16:34, arturturik <artur-uJr1El9zPEmzQB+pC5nmwQ@public.gmane.org> 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 <normsche...-ihVZJaRskl1bRRN4PJnoQQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.