Forum: Ruby on Rails Model attributes that are not backed by persistent storage

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.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-28 21:34
I have a model object that I would like to add an attribute to.

It's an array of other objects.

If I do

  attr_accessor :local_image_tags

should I then be able to assign to object.local_image_tags or read from
object.local_image_tags without incident?

Is ActiveRecord going to assume that there is a table behind these guys?
If so, how do I indicate that these attributes are not stored?

Thanks,
Wes
55428cbf149e35dd4b65f1d019d04139?d=identicon&s=25 Matt Palmer (Guest)
on 2006-03-28 22:35
(Received via mailing list)
On Tue, Mar 28, 2006 at 09:34:09PM +0200, Wes Gamble wrote:
>
> Is ActiveRecord going to assume that there is a table behind these guys?

No.  ActiveRecord *knows* what fields are in the table that underlies
the
object, it doesn't need to assume anything.  Besides, the mechanics of
attributes-as-fields is completely different to attr_accessors.

> If so, how do I indicate that these attributes are not stored?

You don't.  AR knows all about the table and it's structure, and will
ignore
any new and shiny instance attributes you may care to play with.

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