When using an EntityFieldQuery
to retrieve comments, it is not possible to filter them by bundle. To reproduce, simply execute the following code:
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'comment');
$query->entityCondition('bundle', 'comment_node_article');
$result = $query->execute();
This will throw an exception:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'comment.node_type' in 'where clause': SELECT comment.cid AS entity_id, :entity_type AS entity_type, NULL AS revision_id
FROM
{comment} comment
WHERE (comment.node_type = :db_condition_placeholder_0) ; Array
(
[:db_condition_placeholder_0] => comment_node_article
[:entity_type] => comment
)
in EntityFieldQuery->execute() (line 1158 of /var/www/drupal/drupal7/includes/entity.inc).
If something about the above code is just wrong, please correct me, but it seems to work fine with nodes.
Comments
Comment #2
njbarrett CreditAttribution: njbarrett commentedI am also seeing this bug in core 7.41
Comment #3
njbarrett CreditAttribution: njbarrett commentedFor anyone looking for a fix in the meantime, you can add this hook to your module:
NOTE: If the comment bundle condition is not the first condition you may need to change the '0' index of the $conditions array to match your query config.
Then in your EntityFieldQuery do this: