Forum: Ruby on Rails one to one, but only with one table per record

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-05-14 05:57
(Received via mailing list)
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?
Bryan D. (Guest)
on 2006-05-14 06:01
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.
unknown (Guest)
on 2006-05-14 19:05
(Received via mailing list)
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.

This topic is locked and can not be replied to.