Many objects with one query
Gustavo Niemeyer
gustavo at niemeyer.net
Wed Jul 11 21:46:14 BST 2007
Chuck Thier just brought a related question in the channel, and I
added another entry to the tutorial:
==== Many objects with one query ====
Sometimes, it may be interesting to retrieve more than one object involved
in a given query. Imagine, for instance, that besides knowing which
companies have an employee named Ben, we also want to know who is the
employee. This may be achieved with a query like follows:
{{{#!python
>>> result = store.find((Company, Employee),
... Employee.company_id == Company.id,
... Employee.name.like(u"Ben %"))
>>> [(company.name, employee.name) for (company, employee) in result]
[(u'Sweets Inc.', u'Ben Bill')]
}}}
--
Gustavo Niemeyer
http://niemeyer.net
More information about the storm
mailing list