Forum: Ruby ActiveRecord transient fields?

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.
81fc062528fff2d38b393dab081873fe?d=identicon&s=25 PerfectDayToChaseTornados (Guest)
on 2007-03-21 23:35
(Received via mailing list)
Hi All,

Is it possible to have transient fields in a class that extends
ActiveRecord? If so how do I acheive it?

Thanks :-)
D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 Duane Johnson (Guest)
on 2007-03-21 23:52
(Received via mailing list)
I think you're asking if it's possible to add attributes to AR-
derived classes.  Yes:

class Person < ActiveRecord::Base
   attr_accessor :my_transient_field
end

p = Person.new
p.my_transient_field = 1
# the value of my_transient_field will not be stored in the database

Duane Johnson
http://blog.inquirylabs.com/
81fc062528fff2d38b393dab081873fe?d=identicon&s=25 PerfectDayToChaseTornados (Guest)
on 2007-03-22 09:15
(Received via mailing list)
Thanks Duane,

that was exactly what I was asking :-)
This topic is locked and can not be replied to.