user_profiles_tbl and your declarative_meta need to share same MetaData instance.
On Mar 31, 2009, at 9:56 AM, Alexey Maslov wrote: > Michael, > > Thanks for the reply. Sorry, I am incredibly stupid for having > forgotten to replace 'object' with Base. > > Anyway, after I have inherited Country from Base it looks like > SQLAlchemy cannot detect the relation: > URL: http://localhost:5010/pages/subscribe/ > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/WebError-0.10.1-py2.5.egg/weberror/evalexception.py', line > 431 in respond > app_iter = self.application(environ, detect_start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Paste-1.7.2-py2.5.egg/paste/httpexceptions.py', line 636 in > __call__ > return self.application(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/doupy/firepython/ > middleware.py', line 288 in __call__ > app_iter = self._app(environ, faked_start_response) > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/config/ > middleware.py', line 72 in __call__ > return self.app(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/config/ > middleware.py', line 113 in __call__ > resp = self.app(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Beaker-1.2.2-py2.5.egg/beaker/middleware.py', line 81 in > __call__ > return self.app(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Beaker-1.2.2-py2.5.egg/beaker/middleware.py', line 160 in > __call__ > return self.wrap_app(environ, session_start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Routes-1.10.3-py2.5.egg/routes/middleware.py', line 130 in > __call__ > response = self.app(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Paste-1.7.2-py2.5.egg/paste/registry.py', line 350 in > __call__ > app_iter = self.application(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 125 in > __call__ > response = self.dispatch(controller, environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 324 in > dispatch > return controller(environ, start_response) > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/lib/base.py', > line 258 in __call__ > self.request_setup() > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/lib/base.py', > line 298 in request_setup > c.wpuser = setup_request_user(request, get_database) > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/lib/auth.py', > line 48 in setup_request_user > g.read_wordpress_options(db) > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/lib/ > app_globals.py', line 98 in read_wordpress_options > self.siteurl = db.get_wp_option('siteurl') > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/model/db.py', > line 150 in get_wp_option > return get_option() > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/model/db.py', > line 148 in get_option > option = self.query_options.filter_by(option_name=name).one() > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/model/db.py', > line 74 in <lambda> > return property(fget=lambda self: self.session.query(cls)) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/session.py', line > 898 in query > return self._query_cls(entities, self, **kwargs) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 91 in __init__ > self._set_entities(entities) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 100 in _set_entities > self.__setup_aliasizers(self._entities) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 114 in __setup_aliasizers > mapper, selectable, is_aliased_class = _entity_info(entity) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line > 485 in _entity_info > mapper = class_mapper(entity, compile) > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line > 560 in class_mapper > mapper = mapper.compile() > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/mapper.py', line > 662 in compile > mapper._post_configure_properties() > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/mapper.py', line > 691 in _post_configure_properties > prop.init() > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/interfaces.py', > line 408 in init > self.do_init() > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py', > line 709 in do_init > self._determine_joins() > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py', > line 799 in _determine_joins > "many-to-many relation, 'secondaryjoin' is needed as well." % > (self)) > ArgumentError: Could not determine join condition between parent/ > child tables on relation UserProfile.country. Specify a > 'primaryjoin' expression. If this is a many-to-many relation, > 'secondaryjoin' is needed as well. > > The UserProfile class is mapped as: > mapper(UserProfile, user_profiles_tbl, properties={ > 'country' : relation(Country), > 'city' : relation(City), > 'skills' : relation(Skill, > secondary=user_profile_skills_tbl, order_by=Skill.name), > }) > > The Country class is: > Base = declarative_base() > class Country(Base): > __tablename__ = 'countries' > > id = Column(Integer, primary_key=True) > name = Column(Unicode) > alpha2 = Column(Unicode) > order_col = Column(Integer) > ... > > Thanks a lot! > > Regards, > Alexey Maslov > > > On Tue, Mar 31, 2009 at 5:24 PM, Michael Bayer <mike...@zzzcomputing.com > > wrote: > > a class that doesn't extend your declarative base would have to be > mapped explicitly using the mapper() function, otherwise it can't be > referenced within a relation(). > > > On Mar 31, 2009, at 8:04 AM, Alex Maslov wrote: > > > > > Hello, > > > > We have been trying to mix a class inherited from > declarative_base() > > ("Country") with plain Python classes mapped using orm.mapper. We're > > getting the error: > > > > UnmappedClassError: Class 'doupy.model.objects.Country' is not > mapped > > > > code: > > > > Base = declarative_base() > > class Country(object): > > __tablename__ = 'countries' > > ... > > > > Base.metadata.bind = engine > > > > We also tried to create Base using > > Base = declarative_base(bind=engine) > > and > > Base = declarative_base(metadata=meta) > > > > with the same error. > > > > Full traceback below: > > File '/Users/amaslov/Projects/dou-pylons/doupy/doupy/model/ > > __init__.py', line 73 in <lambda> > > return property(fget=lambda self: self.session.query(cls)) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/session.py', line > > 898 in query > > return self._query_cls(entities, self, **kwargs) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 91 > > in __init__ > > self._set_entities(entities) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 100 > > in _set_entities > > self.__setup_aliasizers(self._entities) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line > 114 > > in __setup_aliasizers > > mapper, selectable, is_aliased_class = _entity_info(entity) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line > 485 > > in _entity_info > > mapper = class_mapper(entity, compile) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line > 560 > > in class_mapper > > mapper = mapper.compile() > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/mapper.py', line > > 662 in compile > > mapper._post_configure_properties() > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/mapper.py', line > > 691 in _post_configure_properties > > prop.init() > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/interfaces.py', > > line 408 in init > > self.do_init() > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py', > > line 707 in do_init > > self._get_target() > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py', > > line 719 in _get_target > > self.mapper = mapper.class_mapper(self.argument, compile=False) > > File '/Users/amaslov/Projects/dou-pylons/py/lib/python2.5/site- > > packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line > 557 > > in class_mapper > > raise exc.UnmappedClassError(class_) > > UnmappedClassError: Class 'doupy.model.objects.Country' is not > mapped > > > > Any help is very much appreciated! > > > > Regards, > > Alex > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@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 -~----------~----~----~----~------~----~------~--~---