Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix double {{}} in the ActiveQuery::joinWithRelation() #1638

Closed
Mirocow opened this issue Dec 26, 2013 · 1 comment
Closed

Try to fix double {{}} in the ActiveQuery::joinWithRelation() #1638

Mirocow opened this issue Dec 26, 2013 · 1 comment
Labels
Milestone

Comments

@Mirocow
Copy link

Mirocow commented Dec 26, 2013

private function joinWithRelation($parent, $child, $joinType)
{
    $via = $child->via;
    $child->via = null;
    if ($via instanceof ActiveRelation) {
        // via table
        $this->joinWithRelation($parent, $via, $joinType);
        $this->joinWithRelation($via, $child, $joinType);
        return;
    } elseif (is_array($via)) {
        // via relation
        $this->joinWithRelation($parent, $via[1], $joinType);
        $this->joinWithRelation($via[1], $child, $joinType);
        return;
    }

    $parentTable = $this->getQueryTableName($parent);
    $childTable = $this->getQueryTableName($child);

    if (!empty($child->link)) {

        // Clean if need
        $parentTableLink = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $parentTable);
        $childTableLink = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $childTable);            

        $on = [];
        foreach ($child->link as $childColumn => $parentColumn) {
            $on[] = '{{' . $parentTableLink . "}}.[[$parentColumn]] = {{" . $childTableLink . "}}.[[$childColumn]]";
        }
        $on = implode(' AND ', $on);
    } else {
        $on = '';
    }
    $this->join($joinType, $childTable, $on);


    if (!empty($child->where)) {
        $this->andWhere($child->where);
    }
    if (!empty($child->having)) {
        $this->andHaving($child->having);
    }
    if (!empty($child->orderBy)) {
        $this->addOrderBy($child->orderBy);
    }
    if (!empty($child->groupBy)) {
        $this->addGroupBy($child->groupBy);
    }
    if (!empty($child->params)) {
        $this->addParams($child->params);
    }
    if (!empty($child->join)) {
        foreach ($child->join as $join) {
            $this->join[] = $join;
        }
    }
    if (!empty($child->union)) {
        foreach ($child->union as $union) {
            $this->union[] = $union;
        }
    }
}

}

@qiangxue
Copy link
Member

Thanks!

tonydspaniard added a commit to tonydspaniard/yii2 that referenced this issue Dec 27, 2013
* upstream: (21 commits)
  Fixes yiisoft#1643: Added default value for `Captcha::options`
  Fixes yiisoft#1654: Fixed the issue that a new message source object is generated for every new message being translated
  Allow dash char in ActionColumn’s button names.
  Added SecurityTest.
  fixed functional test when enablePrettyUrl is false.
  fixed composer.json
  minor doc fix.
  Fixes yiisoft#1634: Use masked CSRF tokens to prevent BREACH exploits
  Use better random CSRF token.
  GII unique indexes avoid autoIncrement columns
  updated debug retry params.
  Added sleep().
  Added unit test for ActiveRecord::updateAttributes().
  Fixes yiisoft#1641: Added `BaseActiveRecord::updateAttributes()`
  Fixed yiisoft#1504: Debug toolbar isn't loaded successfully in some environments when xdebug is enabled
  Mongo README.md updated.
  Fixes yiisoft#1611: Added `BaseActiveRecord::markAttributeDirty()`
  Number validator was missing
  Fixes yiisoft#1638: prevent table names from being enclosed within curly brackets twice.
  Unique indexes rules for single columns into array
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants