Hi, SQLAlchemy magic is needed!
I have users table plus two many-to-many relations (skills and cities). I'm trying to implement a search on one or two of these relations. It works fine if I join with skills OR cities but it gives weird error when I'm trying to join both. I suspect my .join() call just incorrect, I'd be very grateful if someone could point out what's wrong with it. Here is the code. relations = ['profile'] if skill: relations.append('skills') if city: relations.append('city') q = self.db.query_users.join(*relations) if skill: q = q.filter(Skill.name == skill) if city: q = q.filter(City.name == city) And the traceback I get when both skill and city are non-empty: File '/var/www/dou-www/doupy/doupy/controllers/members.py', line 263 in browse q = self.db.query_users.join(*relations) File '<string>', line 1 in <lambda> File '/var/www/dou-www/py/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/util.py', line 212 in go return fn(*args, **kw) File '/var/www/dou-www/py/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line 873 in join return self.__join(props, outerjoin=False, create_aliases=aliased, from_joinpoint=from_joinpoint) File '<string>', line 1 in <lambda> File '/var/www/dou-www/py/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line 52 in generate fn(self, *args[1:], **kw) File '/var/www/dou-www/py/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/query.py', line 956 in __join descriptor, prop = _entity_descriptor(left_entity, onclause) File '/var/www/dou-www/py/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/util.py', line 508 in _entity_descriptor desc = entity.class_manager[key] KeyError: 'city' -- Max.Ischenko // twitter.com/maxua --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---