njmacinnes@gmail.com
2006-May-14 01:56 UTC
[Rails] one to one, but only with one table per record
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
Bryan Duxbury
2006-May-14 02:01 UTC
[Rails] Re: one to one, but only with one table per record
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. -- Posted via http://www.ruby-forum.com/.
njmacinnes@gmail.com
2006-May-14 15:03 UTC
[Rails] Re: one to one, but only with one table per record
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 On 14/05/06, Bryan Duxbury <bryan.duxbury@gmail.com> wrote:> 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >