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

Already on GitHub? Sign in to your account

Update framework/db/ar/CActiveRecord.php #2048

Closed
wants to merge 4 commits into
from

Conversation

3 participants
Contributor

s-larionov commented Jan 28, 2013

Если в ActiveRecord переопределить метод getTableAlias, то будут возникать ошибки неизвестной таблицы t, а так он будет использовать текущий алиас у таблицы

Update framework/db/ar/CActiveRecord.php
Если в ActiveRecord переопределить метод getTableAlias, то будут возникать ошибки неизвестной таблицы t, а так он будет использовать текущий алиас у таблицы

@ghost ghost assigned samdark Jan 28, 2013

@cebe cebe commented on the diff Jan 30, 2013

framework/db/ar/CActiveRecord.php
@@ -1294,7 +1294,7 @@ protected function query($criteria,$all=false)
{
if(!$all)
$criteria->limit=1;
- $command=$this->getCommandBuilder()->createFindCommand($this->getTableSchema(),$criteria);
+ $command=$this->getCommandBuilder()->createFindCommand($this->getTableSchema(),$criteria,$this->getTableAlias(false));
@cebe

cebe Jan 30, 2013

Owner

$this->getTableAlias() is enough as false is default for 1st param.
Issue is valid and fix is fine.

@samdark samdark closed this in 356c002 Mar 5, 2013

Owner

samdark commented Mar 5, 2013

Thanks for the fix.

Owner

cebe commented Sep 18, 2013

Whats the actual problem being solved here? This change breaks the logic in createFindCommand(). Issue reported in #2884. Haven't seen the problem before but when getTableAlias() is called the criteria has already been reset and we get the wrong alias. Will revert this change.

Owner

samdark commented Sep 18, 2013

@cebe the original issue was getting unknown table t error in case one overrides ActiveRecord::getTableAlias.

cebe added a commit to cebe/yii that referenced this pull request Sep 18, 2013

Owner

cebe commented Sep 18, 2013

@samdark how got getTableAlias() overridden? There is definitively something wrong in the overriding implementation if it fails.

Owner

cebe commented Sep 18, 2013

Calling getTableAlias() after $this->applyScopes() will give wrong results when alias is set by default scope.
We have to make sure the code works with the default implementation of getTableAlias() before thinking about what happens when it gets overridden. Can you or @s-larionov show an example of how to override getTableAlias() ?

Owner

samdark commented Sep 18, 2013

I guess it's just

public function getTableAlias()
{
  return 'my_cool_alias';
}
Owner

cebe commented Sep 18, 2013

Well, this is definitively not correct as it breaks every code that tries to set alias via criteria.
One should use setTableAlias() or default scope to set a fix alias like this.

cebe added a commit that referenced this pull request Jan 28, 2014

Merge PR #2885 branch 'revert-2048' of https://github.com/cebe/yii
* 'revert-2048' of https://github.com/cebe/yii:
  added changelog line for #2884
  added unit test for #2884
  fixed wrong dependency in unit test
  reverted #2048 as it breaks logic in createFindCommand()

Conflicts:
	CHANGELOG

twiesenthal pushed a commit to twiesenthal/yii that referenced this pull request May 21, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment