I have below query , when it run with non-registered user return null but with any register used with any role has result .
also non-registered user has permission to view any product

$result = db_query("SELECT * FROM {node} node
LEFT JOIN {field_data_field_course_ref} field_data_field_course_ref ON node.nid = field_data_field_course_ref.entity_id AND (field_data_field_course_ref.entity_type = 'node' AND field_data_field_course_ref.deleted = '0')
LEFT JOIN {commerce_product} commerce_product_field_data_field_course_ref ON field_data_field_course_ref.field_course_ref_product_id = commerce_product_field_data_field_course_ref.product_id
WHERE (( (node.nid = :nid ) )AND(( (node.status = '1') AND (node.type IN  ('course_display')) )))
", array(':nid' => $nid));
      $coursePIDs = array();

      //get node product variation 

      foreach ($result as $record) {
        $coursePIDs[$record->field_course_ref_product_id] = $record->field_course_ref_product_id;


any idea?

  • Does turning on query log offer any clues? Anything to do with caching?
    – Felix Eve
    Commented Mar 17, 2014 at 16:47

1 Answer 1


My usual answer for this is product access permissions haven't been set that would allow anonymous users to view all products, but since you're creating this query directly it isn't clear to me that that would be getting in the way. I suppose Drupal is still running query altering on this and somehow alerting the product module that it's involved?

A simple way to rule that out would be to grant anonymous users permission to view any product of any type and see i they get results. But really seeing the query actually run by Drupal would be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.