So, I was eventually able to solve this.
I followed this exact pattern as in my last post:

--- level 0 ; 'myproj_lvl0'---
metadata//Tables
>-plugs-into-<
Base 
\/
OBJ01_Declared_lvl0 > OBJ01_Mapped_lvl0

--- level A ; module 'myproj_lvlA' ---
\/
OBJ01_Extended_lvlA > OBJ01_Mapped_lvlA

--- level B ; module 'myproj_lvlB'---
\/
OBJ01_Extended_lvlB > OBJ01_Mapped_lvlB

The key to the success was really just to,  coming from any higher level 
module, not visit modules of lower levels, which make the mapping concrete 
(i.e. here the OBJ01_Mapped_lvlX declaring modules). This will cause that 
only one mapper is concret for any mapped table at each point of time.

Additionally, if all concrete classes are named the same (the class' 
apparent name, not the fully qualified one), it suffices to use this 
class-name only once in the declaration of the relationship-attributes 
(i.e. writing @declared_attribute def _loc: relationshipd('Location')). 
This will always resolve to the correct mapped class and lifts out a lot of 
possibly duplicated code. The only thing to be observant about is to 
consequently use the '@declared_attr'-decorator.

here is the minimal structure i cam up with:

myproj_lvl0
  | - meta_def [metadata0 Metadata; source_table = Tables(...)]
  | - orm_def [from .meta_def import metadata, source_table; 
Base=declarative_base(metadata); class Source_orm_lvl0(Base): 
@declared_attr __table__ = source_table @declared_attr def _loc: 
relation('Location') ...]
  | - mapper_def [from .orm_def import Source_orm_lvl0; class 
Source(Source_orm_lvl0): pass]
myproj_lvlA
  | - orm_def [from ..myproj_lvl0 import Source_orm_lvl0; 
Source_orm_lvlA(Source_orm_lvl0): @declared_attr def more: ...]
  | - mapper_def [from .orm_def import Source_orm_lvlA; class 
Source(Source_orm_lvlA): pass]
myproj_lvlB
 ...(same structure as lvlB)

scripts
  | - create_tables [from myproj_lvl0.meta_def import metadata; 
metadata.create_all(engine)]
  | - script_lvl0 [from .myproj_lvl0.mapper_def import Source, Location; s 
= session.merge(Source('ABC')); print(type(s._loc)) # 
myproj_lvl0.mapper_def.Location ]
  | - script_lvlA [from .myproj_lvlA.mapper_def import Source, Location; s 
= session.merge(Source('ABC')); print(type(s._loc)) # 
myproj_lvlA.mapper_def.Location]
  | - script_lvlB [from .myproj_lvlB.mapper_def import Source, Location; s 
= session.merge(Source('ABC')); print(type(s._loc)) # 
myproj_lvlB.mapper_def.Location]

I hope that helps if somebody should encounter the same problem

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3495afe7-7f18-41a9-a1d3-b66a884ba50c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to