You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you trying to query all bands for a manager? You can do something like:
frompiccolo.query.methods.selectimportSelectRawawaitManager.select(Manager.name, SelectRaw("ARRAY(SELECT name FROM band where manager = manager.id) AS band_names"))
I didn't get it at first, but it's basically a reverse lokoop. We have PR for that. @dantownsend solution is great for Postgres, but for SQlite (ARRAY is not supported) you can use a less efficient solution like this one (work both sync and async)
managers=Manager.select().run_sync()
bands=Band.select().run_sync()
# Maps manager_id to a list of bandsbands_map= {i[0]: list(i[1]) foriinit.groupby(bands, lambdax: x["manager"])}
rows= []
formanagerinmanagers:
rows.append(
{
"manager": manager["name"],
"bands": [i["name"] foriinbands_map[manager["id"]]],
}
)
print(rows)
Are there any suggestions for one to many queries?
The text was updated successfully, but these errors were encountered: