I came across a little Rails gotcha recently, something that was reported back at least a year ago. I was wondering whether anyone could help me find my way through the bug tracker and see if there was progress on it (I am new to Rails). Here is the bug: You cannot go through a :through association and set a field like this:> paper1.relations_as_source.find_by_id(1).note = "Something"That will return ok, but NOT GET SET! You have to have an intermediary variable first:> rel = paper1.relations_as_source.find_by_id(1) > rel.note = "Something"I would like to ask whether anyone knew the background to this bug (is this intended to work this way, and if so, why?) but of course this may be covered in the bug-tracker, so if anyone can help me find it, that would be great as I''d like to keep tabs on this one. Many many thanks, - Nex --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not a bug. The var= operator does not save information to the database, so your first line is basically wasted resources. You want: paper1.relations_as_source.find_by_id(1).update_attributes(:note => "Something") Jason On 7/26/07, Nex <peterlaurens-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I came across a little Rails gotcha recently, something that was > reported back at least a year ago. I was wondering whether anyone > could help me find my way through the bug tracker and see if there was > progress on it (I am new to Rails). > > Here is the bug: > > You cannot go through a :through association and set a field like > this: > > paper1.relations_as_source.find_by_id(1).note = "Something" > That will return ok, but NOT GET SET! > > You have to have an intermediary variable first: > > rel = paper1.relations_as_source.find_by_id(1) > > rel.note = "Something" > > I would like to ask whether anyone knew the background to this bug (is > this intended to work this way, and if so, why?) but of course this > may be covered in the bug-tracker, so if anyone can help me find it, > that would be great as I''d like to keep tabs on this one. > > Many many thanks, > > - Nex > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ah fantastic - thanks (new to Ruby and Rails). Cheers for the info, - Nex On Jul 26, 5:09 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Not a bug. The var= operator does not save information to the database, so > your first line is basically wasted resources. You want: > > paper1.relations_as_source.find_by_id(1).update_attributes(:note => > "Something") > > Jason > > On 7/26/07, Nex <peterlaur...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I came across a little Rails gotcha recently, something that was > > reported back at least a year ago. I was wondering whether anyone > > could help me find my way through the bug tracker and see if there was > > progress on it (I am new to Rails). > > > Here is the bug: > > > You cannot go through a :through association and set a field like > > this: > > > paper1.relations_as_source.find_by_id(1).note = "Something" > > That will return ok, but NOT GET SET! > > > You have to have an intermediary variable first: > > > rel = paper1.relations_as_source.find_by_id(1) > > > rel.note = "Something" > > > I would like to ask whether anyone knew the background to this bug (is > > this intended to work this way, and if so, why?) but of course this > > may be covered in the bug-tracker, so if anyone can help me find it, > > that would be great as I''d like to keep tabs on this one. > > > Many many thanks, > > > - Nex--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---