function SelectComplexTest::testJoinTwice

Confirms we can join on a single table twice with a dynamic alias.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php, line 325
Definition of Drupal\system\Tests\Database\SelectComplexTest.

Class

SelectComplexTest
Tests more complex select statements.

Namespace

Drupal\system\Tests\Database

Code

function testJoinTwice() {
  $query = db_select('test')
    ->fields('test');
  $alias = $query
    ->join('test', 'test', 'test.job = %alias.job');
  $query
    ->addField($alias, 'name', 'othername');
  $query
    ->addField($alias, 'job', 'otherjob');
  $query
    ->where("{$alias}.name <> test.name");
  $crowded_job = $query
    ->execute()
    ->fetch();
  $this
    ->assertEqual($crowded_job->job, $crowded_job->otherjob, 'Correctly joined same table twice.');
  $this
    ->assertNotEqual($crowded_job->name, $crowded_job->othername, 'Correctly joined same table twice.');
}