I’ve been going back and forth about this kind of thing for a while.
I reverse my opinion on it every project, and I’m wondering if anyone
has any advice/battle scars to share. As usual, please forgive my
long-windedness in advance.
Let’s say I have this:
–Other junk removed for clarity
“category codes”, to the user, are 6-digit numbers, sometimes with
leading zeroes, that have specific meanings.
My customers usually want a metric truckload full of reports. Often,
there are more reports than actual business logic. So much fun.
Reports get much, much easier when you don’t need to join over into a
lookup table constantly.
It would be nice to able able to simply say:
If I follow the ‘pure’ ActiveRecord intent for this, it would instead
…and I would then need to do:
Plans.find(:all, :conditions => “categories.category_code = ‘123456’”,
:include => :categories), which would be much slower.
…and then @some_plan.category.description whenever I needed to
display the description text.
In this design, ‘PLANS.CATEGORY_ID’ would be a non-semantic synthetic
value. Any find_by_sql queries would be much more tedious to write.
Am I going to run into trouble by having my ‘code table’ be an
association with a primary key that actually means something, rather
than being synthetic?
The code works either way, but I hate feeling like I’m going against
the grain with ActiveRecord.
Anyone have any comments or complaints?