Hi,
I'm trying to use entity query to select webformsubmisisons that contain a value in a textfield. My question is how should I call the data-fields?
If I use this condition (ticket_for = field name):
->condition('data.ticket_for',$ADPlusName);
I get this error:
Error: Call to a member function getColumns() on boolean in Drupal\Core\Entity\Query\Sql\Tables->addField() (line 227 of /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php)
#0 /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php(44): Drupal\Core\Entity\Query\Sql\Tables->addField('data.ticket_for', 'INNER', NULL)
#1 /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(155): Drupal\Core\Entity\Query\Sql\Condition->compile(Object(Drupal\Core\Database\Driver\mysql\Select))
#2 /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(74): Drupal\Core\Entity\Query\Sql\Query->compile()
#3 /www/sites/chiro8/chiroD8/web/modules/custom/chiro_events/chiro_events.module(165): Drupal\Core\Entity\Query\Sql\Query->execute()
#4 /www/sites/chiro8/chiroD8/web/modules/custom/chiro_events/chiro_events.module(88): registeredCheck('9', 'Jon Jacobs-1693...')
#5 /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(501): chiro_events_form_alter(Array, Object(Drupal\Core\Form\FormState), 'webform_submiss...')
#6 /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Form/FormBuilder.php(818): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'webform_submiss...')These condtions:
->condition('data',$ADPlusName,'CONTAINS');
->condition('data_ticket_for',$ADPlusName);
->condition('data:ticket_for',$ADPlusName);
Give this error:
Drupal\Core\Entity\Query\QueryException: 'data' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 316 of /www/sites/chiro8/chiroD8/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).
Kind regards and thanks for a fantastic job on the webform module,
Janec
Comments
Comment #2
jrockowitz commentedWebformSubmission data is not stored using Field API. @see #2792583: Use Field API
You would have to query the 'webform_submission_data' table and collect the submission ids (sid) or use the Webform Views module.
Comment #3
taggartj commentedYep but to save you or anyone who is searching for this (means they want to know how to do it)
Comment #4
vunda commentedThis code works only Drupal 7 (array). Any suggestions for Drupal 8. Also, I wondered about memory, maybe json is the best approach.
Comment #5
imclean commented#2
The table "webform_submission_data" uses the EAV model. To extract useful results you can use a static query.
Example SQL to the get
sidmeeting all the requirements:Example static query, supplying the user ID as a variable:
Comment #6
imclean commentedI've created a sandbox module Webform Query to test an idea. It's very basic at the moment but it makes it easier to select submissions by querying submission data.
Comment #7
jrockowitz commented@mclean That is an awesome idea.
I added the Webform Query sandbox module to the Webform's list of add-ons.