Yii Framework Forum: Yii 1.1.13 - Need To Replace T. Alias? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii 1.1.13 - Need To Replace T. Alias? Could someone explain in what places it needs replacing Rate Topic: -----

#1 User is offline   Veseliq 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 21-September 10
  • Location:Sofia, Bulgaria

Posted 31 December 2012 - 07:32 AM

Hey guys,

I upgraded Yii to 1.1.13 and went through the UPGRADE file, as always. The doc says:

Quote

- Criteria modification in CActiveRecord::beforeFind() did not apply to the query when model was loaded in a relational context.
Since version 1.1.13 changes to query criteria made in beforeFind() now also apply to the query when model is loaded in a relational context.
The main problem here is that you can not use the `t`-alias for your table anymore, you have to change your code to
use the table alias currently in use as this is different in relational context.
You can get that alias by calling `$this->getTableAlias();` in your active record class
or `$this->owner->getTableAlias()` in behavior context.

Example:
$criteria->condition = 't.myfield = 1';
You need to change that to:
$alias = $this->owner->getTableAlias();
$criteria->condition = $alias.'.myfield = 1';


Okay, I expected my code to fail where I had used "t." but it didn't. For example the following snippet works as before:
$fuelings = new CActiveDataProvider('Fuelings', array(
    'criteria' => array(
    'condition' => 't.VehicleID=' . $this->VehicleID,
    'with' => array('vehicle')
));


So, when exactly it's does the "t." alias fail and should be replaced?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 01 January 2013 - 07:36 PM

I also confirmed that my existing code with a lot of 't.' aliases works just fine with 1.1.13. :)

I believe that the changes in 1.1.13 won't affect much of the user code, otherwise it would be a huge backward compatibility issue.

Quote

So, when exactly it's does the "t." alias fail and should be replaced?


Yeah, I want to join Veseliq with his question.
UPGRADE text is not very clear and it needs further explanation, IMO.
0

#3 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 02 January 2013 - 11:03 AM

I'm pretty sure this is only relevant if you use the onBeforeFind event.

You can read more here:
http://www.yiiframew...foreFind-detail

Quote

public void onBeforeFind(CModelEvent $event)
$event CModelEvent the event parameter

This event is raised before an AR finder performs a find call. This can be either a call to CActiveRecords find methods or a find call when model is loaded in relational context via lazy or eager loading. If you want to access or modify the query criteria used for the find call, you can use getDbCriteria() to customize it based on your needs. When modifying criteria in beforeFind you have to make sure you are using the right table alias which is different on normal find and relational call. You can use getTableAlias() to get the alias used for the upcoming find call. Please note that modification of criteria is fully supported as of version 1.1.13. Earlier versions had some problems with relational context and applying changes correctly.

1

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 02 January 2013 - 11:17 AM

Thanks, yJeroen. :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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