Forum OpenACS Development: Re: SQL queries 'n TCL

Collapse
8: Re: SQL queries 'n TCL (response to 7)
Posted by Iuri Sampaio on
I just found out the query does not filter by package_id. So, orgs created by users in another org package instance, is not select to the users own orgs list.

SELECT o.organization_id,
o.name,
o.legal_name,
o.reg_number,
o.notes,
ot.type as organization_type
FROM organizations o,
organization_types ot,
organization_type_map tm
WHERE
o.organization_id = tm.organization_id and
o.organization_id in (SELECT ow.organization_id,ow.package_id
FROM organization_owner ow
WHERE ow.user_id = :user_id) and
tm.organization_type_id = ot.organization_type_id and
o.package_id =
[template::list::filter_where_clauses -and -name "orgs"]
[template::list::orderby_clause -orderby -name orgs]
Collapse
9: Re: SQL queries 'n TCL (response to 8)
Posted by Iuri Sampaio on
It's done!
PAtrick and Malte,
It's really great the subselect you two mentioned on this thread.


SELECT o.organization_id,
o.name,
o.legal_name,
o.reg_number,
o.notes,
ot.type as organization_type
FROM organizations o,
organization_types ot,
organization_type_map tm
WHERE
o.organization_id = tm.organization_id and
o.organization_id in (SELECT ow.organization_id
FROM organization_owner ow
WHERE ow.user_id = :user_id) and
tm.organization_type_id = ot.organization_type_id and
o.package_id in (SELECT ow.package_id
FROM organization_owner ow
WHERE ow.organization_id = o.organization_id)

Thanks for the link to the docs. I didn't find before on PG website