Converting node access queries to 7.3
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Previously, for every node listing query, you only needed to add $query->addTag('node_access');
Now, you also need to add $query->addMetaData('base_table', $name_of_table_holding_the_nid);
. For example:
$query = db_select('taxonomy_index', 't');
+ $query->addMetaData('base_table', 'taxonomy_index');
$query->addTag('node_access');
$query->condition('tid', $tid);
As of 7.3, core is able to discover the base table and so this change is optional. However, there's a slight performance hit if the base_table
metadata is not defined explicitly, and in later versions it might become required to specify the base table this way. If your code is doing db_select('node')
then the performance hit is negligible and there are no plans to mandate an $query->addMetaData('base_table', 'node');
for these queries.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion