- I have a webform that I want to grade, like a quiz. (No, not with the Quiz module).
- I have a content type called Answer Key with a Reference field called field_answer_quiz.
Upon webform submission, I want to:
- Look through all nodes of type Answer Key
- Find the one with a field_answer_quiz value == the current webform
- Use node_load() or something to pull out content
Here's a Q&A that makes it seem possible: how to extract values of field collection using Entityfieldquery?
But here's a comment that makes it seem impossible:
If that's what you want, then this is the correct way and
EntityField
does not help you. WhatEntityFieldQuery
does is load entity IDs of entities based on their properties and fields. You could for example use it if you want to load the node(s) that has a specific version value by first loading the field collection item and then loading the node that references the field collection item. You're doing the opposite, you have the node and want the version value. To get field values, you always need to load the entities.
So, which is it? Is it going to be possible for me to use EntityFieldQuery
to do this? I'd really like to avoid having to load a ton of nodes just to shuffle through them.
This is the code I am using.
function webformta_webform_validation_validate($validator_name, $items, $components, $rule) {
$arg = arg();
$nid = $arg[1];
dsm('The NID of the current node is '.$nid);
$query = new EntityFieldQuery;
$result = $query
->entityCondition('entity_type', 'node')
->propertyCondition('status', 1)
->propertyCondition('type', 'quiz_answer_key')
->fieldCondition('field_answer_quiz_nid', 'value', $nid, '=')
->execute();
$results = $query->ordered_results;
dsm($results);
It causes the following error:
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_answer_quiz0.field_answer_quiz_value' in 'where clause': SELECT [...] (error is really really long)
field_answer_quiz
field attached to the node directly or is it attached to a field collection field type?EntityFieldQuery
was pretty much designed for exactly what you're trying to do