Export to GitHub

yii - issue #1183

No way to get table alias from defaultScope


Posted on May 2, 2010 by Massive Cat

Using getTableAlias from defaultScope causes endless loop: getTableAlias calls getDbCriteria that calls defaultScope, which is calling getDbCriteria etc.

http://www.yiiframework.com/forum/index.php?/topic/9036-trying-to-get-table- alias-regularly-crashes/

Comment #1

Posted on May 13, 2010 by Helpful Camel

Actually, it doesn't make sense to call getTableAlias in defaultScope because defaultScope is always the first scope being applied. That means, 't' should always be returned in this case.

Comment #2

Posted on May 13, 2010 by Massive Bird

Yes, but for joined tables with defaultScopes it doesn't work

$basket = Products::model()->with('items')->findAll();

Comment #3

Posted on May 13, 2010 by Helpful Camel

That's right. I will reconsider this limitation. Thanks.

Comment #4

Posted on May 13, 2010 by Helpful Camel

This issue was closed by revision r2131.

Comment #5

Posted on May 13, 2010 by Helpful Camel

You may now call $this->getTableAlias(false,false) in defaultScope() and scopes() to retrieve the currently active table alias. Please let me know if you encounter any problem. Thanks.

Status: Fixed

Labels:
Priority-Medium Milestone-1.1.3