1 database_test.test DatabaseSelectComplexTestCase::testJoinTwice()

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

File

core/modules/simpletest/tests/database_test.test, line 2204
Database tests.

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