Yii1.1.15 Bug - Through & With

  • operating system

Win7

  • Web server

Xampp

  • browser type

Chrome or QQBrowser(IE)

  • Yii version

Yii1.1.15

Background:

My code run normal in Yii1.1.14. When I upgrade framework to 1.1.15 I find below issue.

Issue:

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: ‘scott: the table which duplicated’

Root cause:

After double check, I should find out the root cause: The through & with not handle correctly.

Need Qian and team help to correct it ASAP. Or else, I have to stay at 1.1.14 version with risk

You can duplicate issue as below:

  1. In the model -> relations, I have define some relation with through

public function relations() {

    // NOTE: you may need to adjust the relation name and the related


    // class name for the relations automatically generated below.


    return array(


        'platform' => array(self::BELONGS_TO, 'NPIPlatform', 'Platform_Id'),


        'lob' => array(self::BELONGS_TO, 'NPILob', array('LOB_Id' => 'id'), [b]'through' => 'platform'[/b]),


        'milestone' => array(self::BELONGS_TO, 'NPIMilestone', array('Milestone_id' => 'id'), [b]'through' => 'platform'[/b]),


        'sGCM' => array(self::BELONGS_TO, 'NPIUser', 'SGCM_Id'),


        'partRegion' => array(self::HAS_MANY, 'NPIPartRegion', 'Part_Id'),


        'vendorPrimary' => array(self::BELONGS_TO, 'NPIVendor', 'Vendor_Primary'),


        'commodity' => array(self::BELONGS_TO, 'NPICommodity', 'Commodity_Id'),


        'commCode' => array(self::BELONGS_TO, 'NPICommCode', 'Comm_Code_Id'),


        'platformGSM' => array(self::HAS_ONE, 'NPIUser', array('Platform_GSM_Id' => 'id'), [b]'through' => 'platform')[/b],


    );


}
  1. In the model -> search, I use with to eager load data

$criteria->with = array(

        'platform' => array(


            'select' => 'Platform_Name,Status,RTS_Date,Note'


        ),

[font=“Impact”] ‘platformGSM’ => array(

            'select' => 'username'


        ),


        'milestone',[/font]


        'lob' => array(


            'select' => 'LOB_Name'


        ),


        'commodity' => array(


            'select' => 'Commodity',


        ),


        'commCode' => array(


            'select' => 'Comm_Code',


        ),


        'sGCM' => array(


            'select' => 'username'


        ),


        'vendorPrimary' => array(


            'select' => 'Name'


        )


    );
  1. Then the issue happen, since duplicate npi_platform left out join auto generated.

If I turn of platformGSM, milestone in with, the code will be ok and can run.

I think the yii1.1.15 not handle through and with correctly. Please double check. thanks.

Below is the auto generated SQL code:

Due to duplicated left outer join, it should be handle by Yii team:)

[font="Comic Sans MS"]CDbCommand::fetchColumn() failed: SQLSTATE[42000]: Syntax error or access

violation: 1066 Not unique table/alias: ‘platform’. The SQL statement

executed was: SELECT COUNT(DISTINCT t.id) FROM npi_part t [b]LEFT

OUTER JOIN npi_platform platform ON (t.Platform_Id=platform.id)[/b]

LEFT OUTER JOIN tbl_users platformGSM ON

(platform.Platform_GSM_Id=platformGSM.id) [b]LEFT OUTER JOIN

npi_platform platform ON (t.Platform_Id=platform.id)[/b] LEFT

OUTER JOIN npi_milestone milestone ON

(milestone.id=platform.Milestone_id) [b]LEFT OUTER JOIN

npi_platform platform ON (t.Platform_Id=platform.id)[/b] LEFT

OUTER JOIN npi_lob lob ON (lob.id=platform.LOB_Id) LEFT OUTER

JOIN npi_commodity commodity ON (t.Commodity_Id=commodity.id)

LEFT OUTER JOIN npi_comm_code commCode ON

(t.Comm_Code_Id=commCode.id) LEFT OUTER JOIN tbl_users sGCM ON

(t.SGCM_Id=sGCM.id) LEFT OUTER JOIN npi_vendor vendorPrimary

ON (t.Vendor_Primary=vendorPrimary.id) [/font]

The 1.1.15 release only fixed a security bug in CDetailView. No other code was changed, so I don’t see how the issue you’re experiencing could be related to that specific update. I think you’ll find the problem also occurs in 1.1.14.

You can see the changes in V1.1.15 here.

Yeah, I original think so.

However, the fact is this issue only happen at 1.1.15 since I use the same source code.

You can duplicate the error in 1.1.15 by yourself. Just define 2 or more through relationships and use with for 2 through to eager get data.

The issue occur due to duplicated table SQL auto genarated by Yii1.1.15 when ActiveProvider try to find out records count to render grid. Thanks.

My solution:

Just edit CDetailView to manual upgrade framework from 1.1.14 to 15 by myself :rolleyes:

		//	$value=is_callable($attribute['value']) ? call_user_func($attribute['value'],$this->data) : $attribute['value'];


			$value=is_object($attribute['value']) && get_class($attribute['value']) === 'Closure' ? call_user_func($attribute['value'],$this->data) : $attribute['value'];

Instead download and unzip new framework 1.1.15 to my local

No issue after that.

So, do yii 1.1.15 zip file error? Or not only above line changed in new zip??

Hello,

I know this subject is a little old, but we are upgrading our code now from 1.1.14+ it’s been very stable so why introduce new issues with upgrades; however, the security patch is something we have to do. My question is the same as Scott_Huang. What else changed in the code? As you can see from the attached diff from GIT it appears more than a few lines. And my CDetailView doesn’t match Scott’s or other examples found.

The Yii official Archive doesn’t have 1.1.15 only 1.1.16. I had to pull the 1.1.15 from a third party archive. So what gives?

Any clarity would be helpful. I’d prefer to swap in the few lines of code or just replace the code on the entire page, which is what the attached screenshot is showing.

Thanks in advance!