Debug Drupal query using query_alter
Add your query probably in your custom hook_init()
function mymodule_hook_init() {
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'mybundle')
->propertyCondition('status', 1)
->propertyOrderBy('created', 'DESC')
->fieldCondition('field_news_type', 'tid', '282', '=')
->addTag('efq_debug')
->range(0, 10)
->execute();
}
In the custom module add this
function mymodule_query_alter($query) {
if ($query->hasTag('efq_debug')) {
$sql = (string) $query;
$connection = Database::getConnection();
foreach ((array) $query->arguments() as $key => $val) {
$quoted[$key] = $connection->quote($val);
}
$sql = strtr($sql, $quoted);
dpm($sql);
}
}
Comments
Post a Comment