function DatabaseSelectComplexTestCase::testJoinTwice

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

File

modules/simpletest/tests/database_test.test, line 2433

Class

DatabaseSelectComplexTestCase
Test more complex select statements.

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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.