Polymorphism in SQL database
I find myself faced with a problem that can be summarized as follows:
I have a class "box" which can contain 0-N "Crafts", "Subject" is a common interface to several other classes, with a single point in common is that they may be in the same box. Box may contain multiple instances of the same class, only one instance of several different classes or a mix of both.
This does not pose major problems as I manage it in my program, I'm against a little taken when designing the corresponding tables: How to translate this relationship knowing that I can not create a table with FK object_1 , object_2 ... knowing that I can not know how many there will be objects in each box, create a table join box_id => object_id, as each class will have its own table (they all have separate fields).
Re: Polymorphism in SQL database
It is in Ruby on Rails web framework. Do you think its the problem of Ruby on Rails design? The least worst that I have found yet is to join a table:
- Box_id, object_id, class_name, containing for example:
1, 1, "Shoes"
1, 2, "Shoes"
1, 1, "Bicycle"
The 1st request is beyond what is in box 1, then there would be a request by families of objects:
select * from Shoes where id = 1 or id = 2
select * from Bicycle where id = 1
Given that there will not be hundreds of items per box it's still viable, but I must admit that I'm moderately excited about setting up something
|Tags: database, polymorphism, sql|
|Thread Tools||Search this Thread|
|Similar Threads for: "Polymorphism in SQL database"|
|Thread||Thread Starter||Forum||Replies||Last Post|
|What does polymorphism mean in OOP?||Khan Baba||Software Development||5||06-02-2010 02:14 PM|
|Runtime polymorphism Vs Compile time polymorphism||Owen Fernandes||Software Development||4||03-02-2010 11:06 AM|
|Polymorphism VS Inheritance||Taylor D||Software Development||5||22-01-2010 10:12 AM|
|Is java supports polymorphism?||beelow||Software Development||3||19-11-2009 11:30 AM|
|Function overloading with polymorphism||Mega Member||Software Development||3||02-10-2009 03:35 PM|