0

I want to put extra ON condition

SELECT * FROM users_field_data t1 LEFT JOIN node_field_data t2 ON t1.uid = t2.uid AND t2.type = 'article' and t2.created > 1630491519 WHERE  t2.uid is null;

using my query function

  public function query() {
      $offset_date = new \DateTime("2021-09-01");
      $created = $offset_date->getTimestamp();

      $configuration = [
        'table' => 'node_field_data',
        'field' => 'uid',
        'left_table' => 'users_field_data',
        'left_field' => 'uid',
        'operator' => '=',
      ];

      $offset_date = new \DateTime("2021-09-01");
      $created = $offset_date->getTimestamp();

      $join = Views::pluginManager('join')->createInstance('standard', $configuration);
      $this->query->addRelationship('node_field_data', $join, 'users_field_data');
      $this->query->addWhere('AND', 'node_field_data.nid', '', 'IS NULL');
  }

Where can I add this extra AND t2.type = 'article' and t2.created > 1630491519 statement in the ON clause

0

So using your example, we should be able to modify the $configuration and add an extra key like so:

$configuration = [
  'table' => 'node_field_data',
  'field' => 'uid',
  'left_table' => 'users_field_data',
  'left_field' => 'uid',
  'operator' => '=',
  'extra' => [
    0 => [
        'field' => 'type',
        'value' => 'article',
    ],
    1 => [
        'field' => 'created',
        'value' => $created,
    ],
  ],
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.