One to one, but only with one table per record


#1

Hi,
I have a ‘descriptions’ table which has_one of lots of other tables.
The other tables all belong to a description. But I only want each
description to have one record from any of the tables. So a
description can’t have a room and photo. There has to be one
description for each room, and one description for each photo. Any
idea if there’s a reasonably easy way to enforce this in my model?
Thanks,
-Nathan


#2

You can use polymorphism to make this work.

However, I have to ask, what is special about a description table that
you couldn’t just put it in the room or photo table? It’d be a lot more
efficient in terms of database access, and just make a whole lot more
sense in general.


#3

Thanks, I’ll look into rails polymorphism.

I did have it with description fields in each table (in my first draft
of the table schema), but there’s a lot more to it than I’ve
described, and it would take a lot of effort to explain everything.
You’ll just have to trust me when I say that my reasoning is sound,
and it wouldn’t have worked the other way.

-N