Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

CStatElement with join bugfix #2049

Merged
merged 4 commits into from

2 participants

@Yiivgeny

Model stat-relation defined with ambigous fields:

public function relations() {
    return array(
        'someRelation' => array(
            self::STAT,
            'SomeModel',
            'primary_id',            
            'join' => "JOIN `another_table` AS `r` ON `r`.`primary_id` = `t`.`primary_id`"
        ),
    );
}

throws exception: Integrity constraint violation: 1052 Column 'primary_id' in field list is ambiguous. The SQL statement executed was:

SELECT `primary_id` AS `c`, COUNT(*) AS `s` 
FROM `task` `t` 
JOIN `another_table` AS `r` ON `r`.`primary_id` = `t`.`primary_id`  
WHERE (`t`.`primary_id`='2560') 
GROUP BY `primary_id`
@samdark samdark was assigned
@samdark
Collaborator

Looks good for me. Please add a changelog line and we'll merge it.

CHANGELOG
@@ -14,6 +14,7 @@ Version 1.1.14 work in progress
- Bug #1984: CDbMigration: fix of undeclared variable usage in debug information in dropPrimaryKey (papulovskiy)
- Bug #1996: Using yiic help for commands with parameters with array as default value resulted in PHP error with latest PHP versions (dInGd0nG, samdark)
- Bug #2030: Fixed problem with MySQL 4.x: Undefined Index: Comment in CMysqlSchema (cebe)
+- Bug: CStatElement relation with join option throw exception when key-field present on joined table (Yiivgeny)
@samdark Collaborator
samdark added a note

Need #2049 here and it should be sorted properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@samdark samdark merged commit 479f4cd into from
@samdark
Collaborator

Merged. Thanks!

@Yiivgeny Yiivgeny deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2013
  1. @Yiivgeny

    CStatElement with join bugfix

    Yiivgeny authored
  2. @Yiivgeny

    Adding CHANGELOG line

    Yiivgeny authored
Commits on Jan 29, 2013
  1. @Yiivgeny

    CHANGELOG fixes

    Yiivgeny authored
  2. @Yiivgeny
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +1 −0  CHANGELOG
  2. +1 −1  framework/db/ar/CActiveFinder.php
View
1  CHANGELOG
@@ -14,6 +14,7 @@ Version 1.1.14 work in progress
- Bug #1984: CDbMigration: fix of undeclared variable usage in debug information in dropPrimaryKey (papulovskiy)
- Bug #1996: Using yiic help for commands with parameters with array as default value resulted in PHP error with latest PHP versions (dInGd0nG, samdark)
- Bug #2030: Fixed problem with MySQL 4.x: Undefined Index: Comment in CMysqlSchema (cebe)
+- Bug #2049: CStatElement relation with join option throw exception when key-field present on joined table (Yiivgeny)
- Enh: Better CFileLogRoute performance (Qiang, samdark)
- Enh #1847: Added COutputCache::varyByLanguage to generate separate cache for different languages (Obramko)
- Enh #2038: CFormatter::formatNtext() method can replace newlines with `<p></p>` not just with `<br />` as it was before (resurtm)
View
2  framework/db/ar/CActiveFinder.php
@@ -1398,7 +1398,7 @@ private function queryOneMany()
// generate and perform query
if(count($fks)===1) // single column FK
{
- $col=$table->columns[$fks[0]]->rawName;
+ $col=$tableAlias.'.'.$table->columns[$fks[0]]->rawName;
$sql="SELECT $col AS $c, {$relation->select} AS $s FROM {$table->rawName} ".$tableAlias.$join
.$where.'('.$builder->createInCondition($table,$fks[0],array_keys($records),$tableAlias.'.').')'
." GROUP BY $col".$group
Something went wrong with that request. Please try again.