You are here

function DatabaseSelectComplexTestCase::testJoinTwice in Drupal 7

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

File

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

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