Re: [Modeling-users] Re: Implementing inheritance through vertical mapping
Status: Abandoned
Brought to you by:
sbigaret
From: Federico H. <fh...@vi...> - 2003-10-20 22:36:11
|
Sébastien, On Sat, 2003-10-04 at 11:35, Sebastien Bigaret wrote: > Prerequisite (at least for me:) > * define a sample model, one root entity A, two sub-entities B and > C, and at least one sub-entity D for B (we need a sub-sub-entity to > make sure that the support for vertical mapping will support an > inheritance tree of any depth). Given this sample model, define: > - the derived db-schema, > - SQL statements for selecting, inserting, updating and deleting all > those 4 entities. Well, I've done these, please find them attached. I extended the StoreEmployee model to add a special kind of SalesClerk, the AreaSupervisor who gets a commission on the area's sales. I'm providing the pymodel, the SQL schema as Modiling creates it today, the vertical mapping schema, and the examples. As you might expect, there are no big surprises in any of these... > * have PyModels (and xml, but we can start w/o xml) support flattened > attributes and relationships. I think xml the important part would be to get the back-end to accept dotted-path notation, then pymodel and XML would be just a matter of them allowing the notation. > BTW this is how /I/ think the model would be designed: > - define root entity A, > - define sub-entity B w/ parent=A, > - in sub-entity B, define a to-one rel. 'toA' to the parent; this > relationship will join B's PK to A's PK (and will probably not > be a class property), > - in sub-entity B, flatten every properties of A > (def.='toA.<attrName>' or 'toA.<relName>') I think this relationship should be implicit, i.e. if the user has already stated that B is a subclass of A, no explicit declaration of the relationship should be required. > --> this is for a single level of inheritance. Now it's not clear to > me at all how this should be done when 2+ levels of inheritance > are involved. Should a sub-entity flatten properties from its > direct parent only, or should it flatten its parents > non-flattened properties, then its parent's parent non-flattened > properties, etc. ? That will probably be clearer when we'll have > examples on how this is best done at the SQL level. In keeping with the spirit of the current XML schema, it seems to me that it would be best to flatten every attribute in every class. In such a case, AreaSupervisor's the store_area attribute would be flattened as "toSales_Clerk.store_area" and the first_name would be flattened as "toSales_Clerk.toEmployee.first_name". Actually, if we didn't have multiple nuisance (sorry: inheritance), we could automatically call this relationship "super". > We also need to make sure that defining a PyModel w/ vertical > mapping will be painless. That must not be that difficult, in fact > it should be sufficient to i. detect that a sub-entity has a > different externalName() (db-table's name) than its parent, > ii. automatically append the necessary items in the sub-entity > (toOne rel. to parent, flattened properties). Hmmm... not sure about this one... currently, sub-entities have different externalName()s than their parents (after all, they are different tables!). I can't quite make up my mind whether the choice between vertical and horizontal mapping should be a global option of the model, or decided on an entity-by-entity basis (thus allowing for both kinds of mapping to coexist in the same schema). Fede |