I am constructing a query that has to fetch the field collection line item, and it's associated field collection field to get the node id that the field collection field is being used on. The problem is it's only ever returning one single result when I know for sure there are at least two to return. Perhaps a fresh set of eyes can help.

Run list field table


Run List field's line item table:


This is my query:

$rl_query = db_select('field_data_field_story', 'fci');
$rl_query->fields('fci', array('field_story_target_id', 'bundle', 'entity_id'));
$rl_query->leftJoin('field_revision_field_run_list_item', 'rl', 'rl.field_run_list_item_value = fci.entity_id');
$rl_query->fields('rl', array('entity_id', 'field_run_list_item_value'));
$rl_query->condition('fci.field_story_target_id', $node->nid);
$rl_results = $rl_query->execute()->fetchAll;

When I dpm($rl_results); it ends up looking like:

... (Array, 1 element)
    0 (Object) stdClass
       field_story_target_id (String, 9 characters ) 100000004
       bundle (String, 19 characters ) field_run_list_item
       entity_id (String, 1 characters ) 2
       rl_entity_id (String, 9 characters ) 100000017
       field_run_list_item_value (String, 1 characters ) 2

I should expect to see more than one result returned. In this example, there should be two.


You also put another condition in your query

"$rl_query->condition('fci.field_story_target_id', $node->nid);"

You can check by commenting this line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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