Yii Framework Forum: Yii1.1.15 Bug - Through & With - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Yii1.1.15 Bug - Through & With None unique table/alias Rate Topic: -----

#1 User is offline   Scott_Huang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 18-July 13
  • Location:Xiamen, China

Posted 14 September 2014 - 08:34 AM

- 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'), 'through' => 'platform'),
'milestone' => array(self::BELONGS_TO, 'NPIMilestone', array('Milestone_id' => 'id'), 'through' => 'platform'),
'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'), 'through' => 'platform'),
);
}

2. In the model -> search, I use with to eager load data
$criteria->with = array(
'platform' => array(
'select' => 'Platform_Name,Status,RTS_Date,Note'
),
'platformGSM' => array(
'select' => 'username'
),
'milestone',

'lob' => array(
'select' => 'LOB_Name'
),
'commodity' => array(
'select' => 'Commodity',
),
'commCode' => array(
'select' => 'Comm_Code',
),
'sGCM' => array(
'select' => 'username'
),
'vendorPrimary' => array(
'select' => 'Name'
)
);


3. 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:)


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` LEFT
OUTER JOIN `npi_platform` `platform` ON (`t`.`Platform_Id`=`platform`.`id`)

LEFT OUTER JOIN `tbl_users` `platformGSM` ON
(`platform`.`Platform_GSM_Id`=`platformGSM`.`id`) LEFT OUTER JOIN
`npi_platform` `platform` ON (`t`.`Platform_Id`=`platform`.`id`)
LEFT
OUTER JOIN `npi_milestone` `milestone` ON
(`milestone`.`id`=`platform`.`Milestone_id`) LEFT OUTER JOIN
`npi_platform` `platform` ON (`t`.`Platform_Id`=`platform`.`id`)
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`)

0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 15 September 2014 - 04:09 AM

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.
0

#3 User is offline   Scott_Huang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 18-July 13
  • Location:Xiamen, China

Posted 15 September 2014 - 06:08 AM

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.
0

#4 User is offline   Scott_Huang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 18-July 13
  • Location:Xiamen, China

Posted 16 September 2014 - 12:23 AM

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??
0

#5 User is offline   LasVegas-Inc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 02-August 14

Posted 19 September 2015 - 11:27 AM

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!

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users