Create SelectInterface::leftInnerJoin() and SelectInterface::leftOuterJoin() and make them fluent.

Created on 20 December 2008, over 15 years ago
Updated 7 May 2024, about 2 months ago

Problem/Motivation

Currently we have in the SelectInterface the following methods: join(), innerJoin(), leftJoin() and rightJoin(). They are non-fluent and that makes creating queries with them less beautiful and less readable. So, from:

  $query = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('n.language', $langcode);
  $query->join('field_data_field_home_code', 'hc', 'hc.entity_id = n.nid);
  $nids = $query
    ->condition('hc.field_home_code_value', $house_code)
    ->execute()
    ->fetchCol();

To:

  $nids = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('n.language', $langcode);
    ->join('field_data_field_home_code', 'hc', 'hc.entity_id = n.nid);
    ->condition('hc.field_home_code_value', $house_code)
    ->execute()
    ->fetchCol();

Proposed resolution

  1. The two new methods need to be added to the Drupal\Core\Database\Query\SelectInterface (leftInnerJoin() and leftOuterJoin()). The return value will become $this.
  2. Implement the two new methods in the class Drupal\Core\Database\Query\Select. Use the method addJoin to create their functionality and the return value will be $this.
  3. The two new methods need testing. Use Drupal\KernelTests\Core\Database\SelectComplexTest::testDefaultJoin() and Drupal\KernelTests\Core\Database\SelectComplexTest::testLeftOuterJoin() as examples and create two new tests (testLeftInnerJoinFluent() and testLeftOuterJoinFluent()).
  4. Deprecate the methods join(), innerJoin() and leftJoin() on the Drupal\Core\Database\Query\SelectInterface. The method rightJoin() does not need to be deprecated, because it is already deprecated.
  5. Remove the usages of the methods join(), innerJoin() and leftJoin() in the rest of Drupal core. If the join alias is needed then use the method addJoin(). If he join alias is not needed use the method leftInnerJoin() or leftOuterJoin().

Remaining tasks

  1. Write patch
  2. Review patch
  3. Create a change record

User interface changes

None.

API changes

Yes. Two methods are added to Drupal\Core\Database\Query\SelectInterface (leftInnerJoin() and leftOuterJoin()). Three methods are deprecated on Drupal\Core\Database\Query\SelectInterface (join(), innerJoin(), leftJoin()).

Data model changes

None.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
DatabaseΒ  β†’

Last updated about 9 hours ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡¨πŸ‡¦Canada chx

Live updates comments and jobs are added and updated live.
  • API addition

    Enhances an existing API or introduces a new subsystem. Depending on the size and impact, possibly backportable to earlier major versions.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024