Hello, Is there an equivalent of Hibernate''s UserType feature in ActiveRecord? I have a case where I don''t want the column''s value, but a class instance instance. For instance, this column contains numbers, but this number is just an identifier to a class instance (technically, an enum of sorts). Unfortunately, the DB schema does not contain the lookup table, so I need to emulate returning a class instance instead of the raw number value. Any tips or tricks are much appreciated, Thanks! Seth
Tom Mornini
2005-Sep-19 21:14 UTC
Re: equivalent of Hibernate''s UserType in ActiveRecord?
Why don''t you just override the accessor method and do the translation there? -- -- Tom Mornini On Sep 19, 2005, at 5:02 PM, Seth Ladd wrote:> Hello, > > Is there an equivalent of Hibernate''s UserType feature in > ActiveRecord? I have a case where I don''t want the column''s value, > but a class instance instance. > > For instance, this column contains numbers, but this number is just an > identifier to a class instance (technically, an enum of sorts). > > Unfortunately, the DB schema does not contain the lookup table, so I > need to emulate returning a class instance instead of the raw number > value. > > Any tips or tricks are much appreciated, > Thanks! > Seth > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I seemed to have answered my own question. There is the :composed_of macro, which does what I''d like very closely. http://ar.rubyonrails.com/classes/ActiveRecord/Aggregations/ClassMethods.html#M000232 Sorry for the noise! Seth On 9/19/05, Seth Ladd <sethladd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > Is there an equivalent of Hibernate''s UserType feature in > ActiveRecord? I have a case where I don''t want the column''s value, > but a class instance instance. > > For instance, this column contains numbers, but this number is just an > identifier to a class instance (technically, an enum of sorts). > > Unfortunately, the DB schema does not contain the lookup table, so I > need to emulate returning a class instance instead of the raw number > value. > > Any tips or tricks are much appreciated, > Thanks! > Seth >