简而言之,我需要在运行表达式时执行实体查询。我找不到任何办法来完成这件事。我想应该有两种方法。
下面是我需要完成的一个简单例子
X = content type
y = field on x content type
z = field on x content type
My expression below is just an example, but need to run this in the database query
- Select y and z from x
- if x > y return node id任何帮助都会很好。这将在一个非常大的数据集上运行,试图找到在数据库中执行查询的最快方法。
发布于 2022-03-17 03:55:54
使用实体查询无法比较两个字段。
$query = \Drupal::database()->select('node_field_data', 'n');
$query->condition('n.type', 'x'); // to get content type x
$query->innerJoin('node__field_y', 'y', 'y.entity_id = n.nid'); // join with field y
$query->innerJoin('node__field_z', 'z', 'z.entity_id = n.nid'); // join with field z
$query->where('z.field_z_value > y.field_y_value'); // your condition
$query->addField('n', 'nid'); // get node id in result
$results = $query->execute()->fetchAllKeyed(0, 0);https://stackoverflow.com/questions/71415235
复制相似问题