I’m rebuilding a library/academic system (including public web) using
excellent Rails. I’m trying to make the most out of ActiveRecord, but
rethinking the database schema spawned some potential issues that may
cause problems down the road, so I want thoughts on this from more
experienced community.
The thing is, all entities in the system have a fixed set of metadata.
At first we were copying these columns across entities too keep things
simple:
(these models made simple for illustration purposes)
article = Article.new
article.name = 'foo'
article.source = 'bar'
article.publisher = ....
article.ISBN = 12345
newsitem = News.new
newsitem.title = 'lorem'
newsitem.source = 'bar'
mag = Magazine.new
mag.name = 'ipsum'
mag.publisher = ...
mag.ISBN = ....
After a while, things looked not-so-great. We wanted to move the common
metadata out to a separate table and create associations to it from
every model. That would include the magic columns created/updated_on and
similar. After that, we need to make it possible for entities to have
metadata attributes out from the fixed set if needed, in other words
custom metadata (but that is probably a more complex issue that we
aren’t going to cope with right now).
My goal is to make this technical detail (metadata set moved to the
separate table) transparent to the existing models. For those who don’t
understand me (maybe I’ve put it wrong): I still want to access these
attributes directly, eg.
@event = Colloquium.find(:first)
@event.foo # NOT "event.metadata.foo" !
Also, I want to retain magic functionality of ActiveRecord, like
timestamping (‘created/updated_on’ columns), single table inheritance
(‘type’ column), and so, EVEN if these columns are moved to the metadata
table (as with everything else).
I’ve thought about using views or stored procedures (for more complex
things) for making entities look like they are a single table, but want
to know what others think first.
So, if you have a suggestion how to deal with this metadata issue, feel
free to drop an opinion.
Thanks,
–
Mislav