From: Matthew Wilson <matt@tp...> - 2008-04-27 21:28:33
I've got a table of employees and a table of departments and a related
table that joins the two.
So when I do
for dept in employee.departments:
the SQLObject machinery runs a separate query for each department row.
Sometimes, this is fine, but sometimes, I want to do a query where I
grab every department all at once.
I have been manually adding classmethods when I need the "all-at-once"
join to happen, so then I do:
for dept in employee.get_all_departments_at_once():
Is there a better way to do what I'm doing?
I find that running lots and lots of single queries is really slow, so
in a lot of cases, I prefer to just grab everything.
On Sun, Apr 27, 2008 at 09:28:19PM +0000, Matthew Wilson wrote:
> I've got a table of employees and a table of departments and a related
> table that joins the two.
> So when I do
> for dept in employee.departments:
> the SQLObject machinery runs a separate query for each department row.
What is ".departments"? MultiplJoin? Use SQLMultipleJoin - it runs one
query for one access. It also handles ordering better (can use any SQL
expression). It returns SelectResults instead of a list, but every "for"
loop will happily iterate over it.
Oleg Broytmann http://phd.pp.ru/ phd@...
Programmers don't die, they just GOSUB without RETURN.
Get latest updates about Open Source Projects, Conferences and News.