for this program, move the "managers" property after the compilation  
of the other mappers:

        person_mapper.compile()
        person_mapper.add_property('managers', relation(Manager,  
secondary=people_managers, lazy=False))

this is a workaround for this particular issue.

On Jul 16, 2006, at 5:26 PM, Sol wrote:

> Hello again,
>
>> the mapper associated with select_table is not getting compiled.   
>> this
>> is a product of the simplification to mapper compilation which  
>> compiles
>> all primary mappers when one of them compiles.  bizarely, half a  
>> dozen
>> unit tests dont reproduce the simpler condition here; now there  
>> is.  try
>> revision 1703.
>
> This works smoothly now, thanks:)
>
> However i stumbled upon an other problem. I tried to add a many-to- 
> many
> relationship between Manager and Employee and got an other traceback.
>
> An interactive session with the attached file results in (sa rev   
> 1711):
>
>>>> from polymorphic import *
>>>> create_some_employees()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "polymorphic.py", line 74, in create_some_employees
>     session.save(Manager('Tom', 'knows how to manage things'))
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 416, in init
>     mapper = mapper.compile()
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 152, in compile
>     self._do_compile()
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 175, in _do_compile
>     self._compile_inheritance()
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 222, in _compile_inheritance
>     self.inherits = self.inherits._do_compile()
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 179, in _do_compile
>     self._initialize_properties()
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",  
> line
> 381, in _initialize_properties
>     prop.init(key, self)
>   File "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/mapper.py",
> line 1116, in init
>     self.do_init(key, parent)
>   File
> "/home/sol/sandbox/sqlalchemy/lib/sqlalchemy/orm/properties.py", line
> 207, in do_init
>     self.target = self.mapper.mapped_table
> AttributeError: 'Mapper' object has no attribute 'mapped_table'
>
> I'm still not sure if I'm missing something or if it is a bug. I found
> nothing on mapped_table in the docs or the archives.
>
> Is this related to the broken test case orm.inheritance.InheritTest4?
>
>
> Cheers, Sol.
>
>
> from sqlalchemy import *
>
> db = create_engine('postgres:///satest')
> metadata = BoundMetaData(db)
>
> session = create_session()
>
> class Employee(object):
>     def __init__(self, name):
>         self.name = name
>     def __repr__(self):
>         return self.__class__.__name__ + " " + self.name
>
> class Manager(Employee):
>     def __init__(self, name, manager_data):
>         self.name = name
>         self.manager_data = manager_data
>     def __repr__(self):
>         return self.__class__.__name__ + " " + self.name + " " +   
> self.manager_data
>
> class Engineer(Employee):
>     def __init__(self, name, engineer_info):
>         self.name = name
>         self.engineer_info = engineer_info
>     def __repr__(self):
>         return self.__class__.__name__ + " " + self.name + " " +   
> self.engineer_info
>
>
> people = Table('people', metadata,
>     Column('person_id', Integer, primary_key=True),
>     Column('name', String(50)),
>     Column('type', String(30)))
>
> engineers = Table('engineers', metadata,
>     Column('person_id', Integer, ForeignKey('people.person_id'),  
> primary_key=True),
>     Column('engineer_info', String(50)),
>     )
>
> managers = Table('managers', metadata,
>     Column('person_id', Integer, ForeignKey('people.person_id'),  
> primary_key=True),
>     Column('manager_data', String(50)),
>     )
>
> people_managers = Table('people_managers', metadata,
>     Column('person_id', Integer, ForeignKey("people.person_id")),
>     Column('manager_id', Integer, ForeignKey("managers.person_id"))
> )
>
> person_join = polymorphic_union( {
>     'engineer':people.join(engineers),
>     'manager':people.join(managers),
>     'person':people.select(people.c.type=='person'),
>     }, None, 'pjoin')
>
>
>
>
> person_mapper = mapper(Employee, people, select_table=person_join,  
> polymorphic_on=person_join.c.type, polymorphic_identity='person',
>         properties = dict(managers = relation(Manager,  
> secondary=people_managers, lazy=False))
>         )
>
>
>
> mapper(Engineer, engineers, inherits=person_mapper,  
> polymorphic_identity='engineer')
> mapper(Manager, managers, inherits=person_mapper,  
> polymorphic_identity='manager')
>
>
>
> def create_some_employees():
>     people.create()
>     engineers.create()
>     managers.create()
>     people_managers.create()
>     session.save(Manager('Tom', 'knows how to manage things'))
>     session.save(Engineer('Kurt', 'knows how to hack'))
>     session.flush()
>
>
>
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to