Hello!
How can i create polymorphic associations in GLORP? For example i have a ResourceSnapshot object, which has location. Location could be one of three or more different kind of objects (warehouse, train, ship, plant) (each of them should be represented by different table). So i have to store location_type, location_id like rails does. But how can i use such things with GLORP? Or is there another way to do it? So i want to execute "mySnapshot location" and that message should query database for proper object and create a class for it. Cheers, Oleg |
You can do that, but it'll take you right out of the
pleasant realm of ActiveRecord doing stuff for you fairly automatically.
This is a fairly unpleasant thing to do in relational databases, where
polymorphism isn't part of the vocabulary, and having a foreign key that
goes to one of several tables is actively fighting against the relational
model, and will prevent you from using things like foreign key
constraints.
So basically you have two choices. If you have a horizontal inheritance relationship between the classes, then some of that will get done automatically. But you'd still need to define a VariableJoin for the join on the mapping. In GlorpTest, GlorpInheritanceDescriptorSystem and GlorpHorizontalInheritanceTest have examples, such as they are. Or, and this is probably easier for a one to one type of relationship, you can define a ConditionalMapping based on the type field. Something like locationMapping := aDescriptor newMapping: ConditionalMapping. locationMapping and repeating the if:useMapping: clauses as necessary. Yes, this could be a lot more pleasant, especially for fairly simple cases like this. At 03:58 PM 3/29/2008, Oleg Richards wrote: Hello! --
Alan Knight [|], Cincom Smalltalk Development
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Thank you very much, Alan.
You've told me, that it' fairly unpleasant thing to do in relational databases, but what can i do in that case? How do you recommend me to restructure my data? So i have to store locations of my resource and i need that location to be an object with its own behavior. And i also need to have an actions for resources on that objects. For example: Ammonium - Railroad - Transferring, Ammonium - Railroad - Unloading, Ammonium - Warehouse - Storing, etc. Oleg
|
Free forum by Nabble | Edit this page |