Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
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.
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())
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"
> 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
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.
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?
Comments
Comment #1
gielfeldt commentedCan you elaborate a bit?
Comment #2
gielfeldt commentedAre 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.
Comment #3
geek-merlinhmm, 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())
Comment #4
gielfeldt commentedInitially 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()?
Hmmm .... not sure what you have in mind.
Comment #5
geek-merlin> 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
Comment #6
gielfeldt commented> 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?
Comment #7
gielfeldt commentedHi 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?
Comment #8
gielfeldt commentedComment #9
gielfeldt commentedI think this a better way to go: #1862032: Provide helpers for entity hierarchies
Comment #10
gielfeldt commented