[Catalyst] flexible attributes on db objects
Daniel McBrearty
danielmcbrearty at gmail.com
Fri Jun 8 10:48:02 GMT 2007
as my app is developing I'm seeing more and more that having
flexibility in the db layer is one of the things that saves a lot of
stress and hassle.
something that happens a lot is that you get the basic objects and
relationships between them correct, but don't know all the attributes
that they will need until later. so (thanks Alan Humphrey for this)
there is a way (that is likely not new to many people here) ... :
TABLE my_object {
id INTEGER PRIMARY KEY,
.
. // whatever
.
};
TABLE my_object_attributes {
id INTEGER PRIMARY KEY,
name TEXT
}
TABLE my_object_attributes {
my_object_id REFERENCES my_object(id),
attribute_id REFERENCES my_object_attributes(id)
text_value TEXT,
number_value NUMBER
}
so now you have a way to add a new attribute to the object, and have
any instance then have a text/number value for that.
You can also write some API functions in the db layer to
create/assign/delete attributes, taking table name as an arg. So at
the cost of two tables for the object, you move a lot of design
decisions downstream.
Comments? horrendous hackery? laziness? a landmine? ok in some cases?
cheers
Daniel
--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com
danmcb.vox.com
danmcb.blogger.com
BTW : 0873928131
More information about the Catalyst
mailing list