Forum: Ruby on Rails Fat Data Model vs Skinny Data Model

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.
032fdb4cd4a3c65ebb77846dfa724679?d=identicon&s=25 Joe Noon (Guest)
on 2006-04-07 14:49
(Received via mailing list)
Ive recently been contemplating how to tackle allowing for extra
"fields" to be added to a recordset. For example, a user has an email
address, but they may also want to put their birthday, height, weight,
etc.  I don't want to constrain what is possible in this situation.  I
think what I'm describing is best documented in Philip Greenspun's
page here:

http://philip.greenspun.com/seia/user-registration...

Now, I'm not entirely sure this is the best approach, I'm open to
suggestions on how to deal with the situation.  What I would like to
know though is:  Is this something that could be an extension of the
ActiveRecord class?  Lets say its called ActiveSkinnyRecord or
something... is there a potential to make tables with this setup be
just as easily dealt with as ActiveRecord does?  Id be willing to give
it a shot if it makes sense to others, and is doable.  Please let me
know your thoughts.

Joe Noon
B13a9240291ffa22215214316bd365de?d=identicon&s=25 Hendrik Mans (Guest)
on 2006-04-07 14:58
(Received via mailing list)
On 4/7/06, Joe Noon <joenoon@gmail.com> wrote:
> Ive recently been contemplating how to tackle allowing for extra
> "fields" to be added to a recordset. For example, a user has an email
> address, but they may also want to put their birthday, height, weight,
> etc.  I don't want to constrain what is possible in this situation.

You have at least three strategies available that you can use right
now without any futher additions to AR:

1.) Single Table Inheritance (admittedly not 100% what you're looking
for, but it's worth a mention anyway)
2.) has_many :attributes, :as => :attributable (polymorphic
relationship with a simple Attribute model)
3.) serialize :attributes (where User#attributes is a Hash that is
YAML'd into a TEXT column transparently.)

Go wild!

--
http://www.mans.de
032fdb4cd4a3c65ebb77846dfa724679?d=identicon&s=25 Joe Noon (Guest)
on 2006-04-07 22:10
(Received via mailing list)
> 2.) has_many :attributes, :as => :attributable (polymorphic
> relationship with a simple Attribute model)

Thanks Hendrik, I will check that out.  I think the serialized way
while it may be convenient would probably be a bad deal for general
record finding/sorting... too bad cause that would be a real simple
solution.

Joe
This topic is locked and can not be replied to.