我正试图离开entity_id,但只收到一个没有细节的错误。
Drupal中的entity_id是否有一个技巧?
$query = db_query('SELECT COUNT(n.field_feed_vehicle_code_value) FROM {field_data_field_feed_vehicle_code} n LEFT JOIN {field_data_field_feed_vehicle_date_used} du ON n.entity_id = du.entity_id WHERE n.field_feed_vehicle_code_value = :utilization AND du.field_feed_vehicle_date_used = :utilization_date', array(':utilization' => $fieldVehicleCode, ':utilization_date' => $fieldDVIRDate))->fetchField();
我发现了其他关于leftjoins的问题,但实际上没有关于entity_id的问题。我也发现了这个Drupal 7 select query with joins但是这个解决方案也没有用。
$query = db_select('node', 'n');
$query->leftJoin('field_data_field_feed_vehicle_code', 'vc', 'n.nid = vc.entity_id');
$query->leftJoin('field_data_field_feed_vehicle_date_used', 'du', 'n.nid = du.entity_id');
$query
->fields('n', array('nid'))
->fields('vc.field_feed_vehicle_code_value', $fieldVehicleCode , '=')
->fields('du.field_feed_vehicle_date_used', $fieldDVIRDate , '=')
->condition('type', 'dvir_utilization_feed')
->condition('status', 1)
->execute();
$num = $query->rowCount();
答案 0 :(得分:0)
我相信你想用
->condition('vc.field_feed_vehicle_code_value', $fieldVehicleCode , '=')
->condition('du.field_feed_vehicle_date_used', $fieldDVIRDate , '=')
因为这不是->fields
答案 1 :(得分:0)
我最终得到了错误的字段名称并且必须执行db_query,尽管我更喜欢db_select。
$query = db_query('SELECT COUNT(vc.field_feed_vehicle_code_value)
FROM {node} n
LEFT JOIN {field_data_field_feed_vehicle_code} vc ON n.nid = vc.entity_id
LEFT JOIN {field_data_field_feed_vehicle_date_used} du ON n.nid = du.entity_id
WHERE vc.field_feed_vehicle_code_value = :utilization
AND du.field_feed_vehicle_date_used_value = :utilization_date',
array(':utilization' => $fieldVehicleCode, ':utilization_date' => $fieldDVIRDate))->fetchField();
$utilization = $query;