Forum: Ruby on Rails Little Rails Bug - does it still exist?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nex (Guest)
on 2007-07-26 20:07
(Received via mailing list)
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
Jason R. (Guest)
on 2007-07-26 20:09
(Received via mailing list)
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
Nex (Guest)
on 2007-07-26 20:15
(Received via mailing list)
Ah fantastic - thanks (new to Ruby and Rails).

Cheers for the info,

- Nex
This topic is locked and can not be replied to.