Wes Gamble
2006-Mar-28 20:59 UTC
[Rails] Model attributes that are not backed by persistent storage
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 -- Posted via http://www.ruby-forum.com/.
Matt Palmer
2006-Mar-28 21:12 UTC
[Rails] Re: Model attributes that are not backed by persistent storage
On Tue, Mar 28, 2006 at 09:34:09PM +0200, Wes Gamble wrote:> 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?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
Reasonably Related Threads
- Session mgmt. bug - ActiveRecord & MemoryStore session store
- Re: Some advice on DB modeling
- Does text_field go directly to attributes hash in AR object?
- text_field doesn''t call overridden ActiveRecord getters
- Wrap error_messages_for() call when no instance var present