0

When we build a view from the view ui, we can show what is the "hard query" is executed, example :

SELECT node__field_house_count_added.field_house_count_added_value AS node__field_house_count_added_field_house_count_added_value, node_field_data.nid AS nid
FROM 
{node_field_data} node_field_data
INNER JOIN {node__field_house_tags} node__field_house_tags_value_0 ON node_field_data.nid = node__field_house_tags_value_0.entity_id AND node__field_house_tags_value_0.field_house_tags_target_id = '4'
INNER JOIN {node__field_house_tags} node__field_house_tags_value_1 ON node_field_data.nid = node__field_house_tags_value_1.entity_id AND node__field_house_tags_value_1.field_house_tags_target_id = '5'
INNER JOIN {node__field_house_tags} node__field_house_tags_value_2 ON node_field_data.nid = node__field_house_tags_value_2.entity_id AND node__field_house_tags_value_2.field_house_tags_target_id = '16'
INNER JOIN {node__field_house_tags} node__field_house_tags_value_3 ON node_field_data.nid = node__field_house_tags_value_3.entity_id AND node__field_house_tags_value_3.field_house_tags_target_id = '6'
LEFT JOIN {node__field_house_count_added} node__field_house_count_added ON node_field_data.nid = node__field_house_count_added.entity_id AND (node__field_house_count_added.deleted = '0' AND node__field_house_count_added.langcode = node_field_data.langcode)
WHERE ((( (node__field_house_tags_value_0.field_house_tags_target_id = '4') AND (node__field_house_tags_value_1.field_house_tags_target_id = '5') AND (node__field_house_tags_value_2.field_house_tags_target_id = '16') AND (node__field_house_tags_value_3.field_house_tags_target_id = '6') )))
ORDER BY node__field_house_count_added_field_house_count_added_value DESC
LIMIT 2 OFFSET 0

Is there a way for get quickly the query, but in the query api format ? Like :

$query = db_select('users', 'u')
  ->condition('u.uid', 0, '<>')
  ->fields('u', array('uid', 'name', 'status', 'created', 'access'))
  ->range(0, 50);

Thanks :)

1 Answer 1

0

No, there is not.

You're also not supposed to write a query directly against entity or field tables yourself. Use the entity query API instead:

https://www.sitepoint.com/drupal-8-version-entityfieldquery/

$uids = \Drupal::entityQuery('user')
  ->condition('uid', 0, '<>',
  ->range(0, 50)
  ->execute();

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.