think since d7 we have hook_query_alter and friends.

Comments

gielfeldt’s picture

Can you elaborate a bit?

gielfeldt’s picture

Are you thinking about implementing e.g. hook_query_term_access_alter() in order to avoid the core patch? If so, I'm not sure this would be possible, as the query is unaware of $parent. Also the static caching within taxonomy_get_tree() assumes all terms are fetched for a given vocabulary. Would have been nice though.

geek-merlin’s picture

hmm, just thinking aloud:
* we might be able to do all insert and update queries with suitable hook_query_alter()
http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct...
(although i don't know if there are issues with making multiple queries out of one)
* it might be cool to factor this out as a generalized "relation closure helper"
* (looks like for taxonomy a patch is still needed to have a better taxonomy_get_tree())

gielfeldt’s picture

we might be able to do all insert and update queries with suitable hook_query_alter()

Initially I made it using MySQL triggers, so this would seem like a reasonable substitute for that. Then it would also support modules bypassing the taxonomy api and accessing the tables directly (like Taxonomy Manager). Does hook_query_alter() work with db_query()?

it might be cool to factor this out as a generalized "relation closure helper"

Hmmm .... not sure what you have in mind.

geek-merlin’s picture

> Does hook_query_alter() work with db_query()?
yes, that's its goal.

>it might be cool to factor this out as a generalized "relation closure helper"
the same can be applied to
* hierarchical taxonomy
* entities with a "parent" ref field
* entities connected by a "parent-child" relation

gielfeldt’s picture

> Does hook_query_alter() work with db_query()?

hook_query_alter() seems to need a "tag" on the query in order to alter it, which is usually not set (or impossible to set?) when using db_query() as opposed to db_select/db_insert/etc.

Am I doing something wrong you think?

gielfeldt’s picture

Hi Axel

What about this idea? Is it still worth pursuing? (and if so how do you suggest we proceed?) I'm a bit worried that we won't have enough contextual knowledge in the db-layer. Perhaps the Tree module (with tree field) is a better candidate for generalizing this?

gielfeldt’s picture

Status: Active » Postponed (maintainer needs more info)
gielfeldt’s picture

I think this a better way to go: #1862032: Provide helpers for entity hierarchies

gielfeldt’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)