Hello,

The site on which I work uses the organic groups (og) module. It implements the rewrite_sql hook so that all node/comment/whatever queries only return those which have proper permissions under the og permission system. I have created a view which lists a certain set of nodes, but the SQL isn't be rewritten as I expect. Here is the SQL before the rewrite:

SELECT node.nid FROM {node} node  LEFT JOIN {buddylist} buddylist ON node.uid = buddylist.buddy LEFT JOIN {users} buddylist_users ON buddylist.uid = buddylist_users.uid WHERE (node.status = '1') AND (buddylist_users.uid = '12436') AND (node.type  IN ('blog','poll'))  ORDER BY node.created DESC

After the rewrite the only difference is replacing node.nid with DISTINCT(node.nid). Is there something about how this SQL is written that is preventing og from rewriting it properly? It works on other, hand-crafted queries.

Any thoughts?

Thanks.

Comments

moshe weitzman’s picture

- make sure you don't have administer nodes permission
- make sure you run the SQL through db_rewrite_sql() before db_query().

farmerje’s picture

Ah, I think the former might be it! Silly me, and many thanks.