Converting node access queries to 7.3

Last updated on
15 October 2016

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->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.