Hi I''ve just started looking into building a rails frontend to a database project I''ve been working on but I need some help with how to convert some parts of the database. The database got a bunch of tables each describing a different type of entity and each of these entities can have several comments. I''ve solved this by giving all entities an identifier through a master identifier table (entityId1 --> masterId, entityId2 --> masterId) but I can''t think of any way to get this working in rails and also it''s kinda an ugly hack in my opinion. Any thoughts on this? Thought of using some sort of guid but most people seem to think it''s not worth it? // Andreas
2009/10/2 Andreas <adde.falk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Hi > > I''ve just started looking into building a rails frontend to a database > project I''ve been working on but I need some help with how to convert > some parts of the database. > > The database got a bunch of tables each describing a different type of > entity and each of these entities can have several comments. I''ve > solved this by giving all entities an identifier through a master > identifier table (entityId1 --> masterId, entityId2 --> masterId) but > I can''t think of any way to get this working in rails and also it''s > kinda an ugly hack in my opinion. > > Any thoughts on this? Thought of using some sort of guid but most > people seem to think it''s not worth it?_If_ I understand I think you might want to look at polymorphic relationships. http://wiki.rubyonrails.org/howtos/db-relationships/polymorphic might be a good start. This would allow your different model types all to have comments without repeating the code everywhere. Colin
That seems to do it. Thanks for the help! // Andreas On Oct 2, 7:34 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/10/2 Andreas <adde.f...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > > > Hi > > > I''ve just started looking into building a rails frontend to a database > > project I''ve been working on but I need some help with how to convert > > some parts of the database. > > > The database got a bunch of tables each describing a different type of > > entity and each of these entities can have several comments. I''ve > > solved this by giving all entities an identifier through a master > > identifier table (entityId1 --> masterId, entityId2 --> masterId) but > > I can''t think of any way to get this working in rails and also it''s > > kinda an ugly hack in my opinion. > > > Any thoughts on this? Thought of using some sort of guid but most > > people seem to think it''s not worth it? > > _If_ I understand I think you might want to look at polymorphic > relationships.http://wiki.rubyonrails.org/howtos/db-relationships/polymorphicmight > be a good start. This would allow your different model types all to > have comments without repeating the code everywhere. > > Colin