I'm trying to do a select of columns from a join and I simply can't get it
to work. I have tried various different ways to specify the join, with and
without a select_from() and I can't find a combination that works.
the tables look like
class Dealer(Base):
__tablename__ = 'dealers'
id = Column(String(64), primary_key=True, nullable=False)
name =Column(String(100), nullable=False)
phone_number = Column(String(64), nullable=False)
def __repr__(self):
return "<Dealer(supplying_dealer='%s', registration='%s',
servicing_dealer='%s')>" % (
self.supplying_dealer, self.registration,
self.servicing_dealer)
class Vehicle(Base):
__tablename__ = 'vehicles'
registration = Column(String(10), primary_key=True, nullable=False)
supplying_dealer = Column(String(64), ForeignKey(u'dealers.id'),
nullable=False)
servicing_dealer = Column(String(64), ForeignKey(u'dealers.id'),
nullable=False)
def __repr__(self):
return "<Vehicle(registration='%s', supplying_dealer='%s',
servicing_dealer='%s')>" % (
self.registration, self.supplying_dealer, self.servicing_dealer)
and I have tried lots of variations on:
for supplier, phone, registration in
session.query(Dealer.name,Dealer.phone_number,Vehicle.registration).select_from(Vehicle).join('supplying_dealer'):
print( supplier, phone, registration )
I haven't found a combination that works. Am I missing the obvious?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.