/**
  * @override
  */
 public function root($root, $alias = null)
 {
     parent::root($root, $alias);
     $table = $this->_table->name;
     $alias = $alias ?: $this->getRootAlias();
     $this->setJoinClause($alias, new JoinClause($table, $alias));
     return $this;
 }
 public function root($root, $alias = null)
 {
     parent::root($root, $alias);
     if (!$this->_useModel) {
         $this->_components['updateFrom'] = $root;
         return $this;
     }
     $joinClause = new JoinClause($this->_table->name, $this->getRootAlias());
     $this->_components['updateFrom'] = array($joinClause);
     return $this;
 }
 public function root($root, $alias = null)
 {
     parent::root($root, $alias);
     if (!$this->_useModel) {
         $this->_components['deleteFrom'] = $root;
         return $this;
     }
     // Using several tables is not yet possible with delete builder. Thus,
     // we set the table name in "deleteFrom" component. We won't bother with
     // any table alias.
     $this->_components['deleteFrom'] = $this->_table->name;
     return $this;
 }
 public function testWhereRelation()
 {
     $b = new WhereBuilder();
     $b->root('Article', 'articles');
     $b->whereRelation(Blog::relation('articles'), '_');
     $components = $b->build();
     $where[] = ['type' => 'Attribute', 'lTable' => 'articles', 'lCols' => ['blog_id'], 'op' => '=', 'rTable' => '_', 'rCols' => ['id'], 'logic' => 'AND'];
     $this->assertEquals($where, $components['where']);
     $this->assertEquals(Blog::table(), $b->getInvolvedTable('_'));
     // - - -
     // With many-to-many relation.
     $rel = Article::relation('readers');
     $mdName = $rel->getMiddleTableName();
     $mdAlias = $rel->getMiddleTableAlias();
     $b = new WhereBuilder();
     $b->root('User', 'readers');
     $b->whereRelation($rel, '_');
     $components = $b->build();
     $jc = new JoinClause($mdName, $mdAlias);
     $jc->on('readers', 'id', $mdAlias, 'user_id');
     $where = [['type' => 'Attribute', 'lTable' => $mdAlias, 'lCols' => ['article_id'], 'op' => '=', 'rTable' => '_', 'rCols' => ['id'], 'logic' => 'AND']];
     $this->assertEquals($where, $components['where']);
     $this->assertEquals(Article::table(), $b->getInvolvedTable('_'));
     $this->assertEquals($jc, $b->getJoinClause($mdAlias));
     try {
         $b->getJoinClause('_');
         $this->fail('Should have thrown an exception.');
     } catch (Exception $ex) {
         $this->assertContains('_', $ex->getMessage());
     }
 }