Hi All,
The script at the end of this message blows up with:
sqlalchemy.exc.InvalidRequestError: When compiling mapper
Mapper|Employee|employee, expression 'Organisation' failed to locate a
name ("name 'Organisation' is not defined"). If this is a class name,
consider adding this relation() to the <class '__main__.Employee'> class
after both dependent classes have been defined.
...unless the line preceded with #yuk is present.
Why does declarative store this information in its own registry rather
than using the MetaData to do so?
Is there a nicer way I can achieve this result? I have multiple bases
since Michael suggested this was the right way to go to have base
classes for mapped classes that do nothing but contain common field
definitions and functionality...
cheers,
Chris
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relation, sessionmaker
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String, DateTime
engine = create_engine('sqlite://')
metadata = MetaData()
Base1 = declarative_base(metadata=metadata)
Base2 = declarative_base(metadata=metadata)
# yuk
Base2._decl_class_registry=Base1._decl_class_registry
class Employee(Base1):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
name = Column(String(1000), nullable=False, index=True)
org = relation("Organisation")
org_id = Column(Integer, ForeignKey('organisation.id'))
class Organisation(Base2):
__tablename__ = 'organisation'
id = Column(Integer, primary_key=True)
name = Column(String(50))
employees = relation("Employee")
metadata.create_all(engine)
o = Organisation(name='SomeOrg')
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.