query.join() takes an onclause as in the following: query.join((target, onclause), (target2, onclause2), ...)
the onclause can be an expression or a named relation. see the examples in http://www.sqlalchemy.org/docs/05/ormtutorial.html#querying-with-joins . On May 27, 2009, at 11:54 AM, Marcin Krol wrote: > > Hello everyone, > > Is there such a thing? > > I have to specify onclause since Host <-> Reservation is many-to-many, > and if I don't specify onclause, I get exception "Can't find any > foreign > key relationships between 'reservation' and 'hosts'". > > Docs: > > "The onclause may be a string name of a relation(), or a class-bound > descriptor representing a relation." > > What does "class-bound descriptor representing a relation" mean > anyway?? > > This results in exception: > >>>> rsvs = session.query(Reservation, > Host > ).filter > (Reservation.project_id.in_(projids)).filter(Reservation.status > == 'pending').join(Host, onclause='hosts').all() > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 1, in <lambda> > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/util.py", > line 212, in go > return fn(*args, **kw) > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/orm/query.py", > line 869, in join > raise TypeError("unknown arguments: %s" % > ','.join(kwargs.iterkeys())) > TypeError: unknown arguments: onclause > > I do in fact have 'hosts' relation in Reservation: > > mapper(Reservation, reservation_table, > properties={'email':relation(Email,order_by=Email.id), > 'project':relation(Project, order_by=Project.id), > 'hosts':relation(Host, > secondary=reservation_hosts_assoc_table,backref='reservation'), > 'newhosts':relation(NewHost, > secondary=reservation_newhosts_assoc_table,backref='reservationnh')} > ) > > So it's either onclause that is truly unknown to join() or smth else > throws it off. > > > I even tried this, don't know if it makes sense: > > >>>> rsvs = session.query(Reservation, Host).join(Host, > onclause > = > 'hosts > ').filter > (Reservation.project_id.in_(projids)).filter(Reservation.status > == 'pending').all() > > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 1, in <lambda> > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/util.py", > line 212, in go > return fn(*args, **kw) > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/orm/query.py", > line 869, in join > raise TypeError("unknown arguments: %s" % > ','.join(kwargs.iterkeys())) > TypeError: unknown arguments: onclause > > > > >>>> rsvs = session.query(Reservation).join(Host, >>>> onclause='hosts').all() > > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 1, in <lambda> > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/util.py", > line 212, in go > return fn(*args, **kw) > File > "/usr/local/lib/python2.6/site-packages/SQLAlchemy-0.5.3-py2.6.egg/ > sqlalchemy/orm/query.py", > line 869, in join > raise TypeError("unknown arguments: %s" % > ','.join(kwargs.iterkeys())) > TypeError: unknown arguments: onclause > > > Regards, > mk > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---