Hi, I have this simple model:
class DHCPServer(DeclarativeBase):
__tablename__ = 'dhcp_server'
id = Column(Integer, primary_key = True)
hostname = Column(Unicode(80), nullable = False)
ip = Column(Unicode(16), nullable = False)
label = Column(Unicode(80))
class WorkStation(DeclarativeBase):
__tablename__ = 'work_stations'
id = Column(Integer, primary_key = True)
hostname = Column(Unicode(255), nullable = False)
ip = Column(Unicode(16), nullable = False)
mac = Column(Unicode(17), nullable = False)
timestamp = Column(DateTime, nullable = False)
server_id = Column(Integer, ForeignKey('dhcp_server.id'))
server = relation(DHCPServer)
Now I want to build a query to get all Workstations which are related
to server 'foo'.
This works:
ws = DBSession.query(WorkStation).select_from(join(WorkStation,
DHCPServer)).filter(DHCPServer.label == 'foo').all()
but It's too complex. Is there an easier way?
Something like:
DBSession.query(WorkStation).filter(Workstation.server.label ==
'foo').all()
Thanks!
--
Diego Woitasen
XTECH
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---