# One to one, but only with one table per record

**URL:** <https://www.ruby-forum.com/t/one-to-one-but-only-with-one-table-per-record/94777>\
**Category:** Rails\
**Created:** [May 14, 2006, 3:57am UTC](https://www.ruby-forum.com/t/one-to-one-but-only-with-one-table-per-record/94777 "2006-05-14T03:57:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2006, 3:57am UTC](https://www.ruby-forum.com/t/one-to-one-but-only-with-one-table-per-record/94777/1 "2006-05-14T03:57:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2006, 4:01am UTC](https://www.ruby-forum.com/t/one-to-one-but-only-with-one-table-per-record/94777/2 "2006-05-14T04:01:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/one-to-one-but-only-with-one-table-per-record/94777/3 "2006-05-14T17:05:24Z")

</div>

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
