Yii Framework Forum: why was default alias for default table changed? - Yii Framework Forum

Jump to content

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

why was default alias for default table changed? Rate Topic: -----

#1 User is offline   horizons 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 18-December 08

Posted 12 January 2010 - 05:45 AM

As in the lastest Version:
- The alias name for the primary table in an AR query is fixed to be 't'

Why was this introduced?
My problem I have several Sql queries by hand and also build with the schema builder and now have to fix all sort orders and condition queries.

Which is not that easy and much work.
Why was this introduced and is there anything to set it back to the tablename itself?

I tried 1.1rc and had no problem with this, but after updating to the released 1.1 nothing works :S


Also i find it quite enoying that following works
$criteria=new CDbCriteria;
$criteria->condition=("`post`.`title` LIKE '%test%'");
$criteria->select =array('title','content');

// setting alias by hand to the same as in condition
$criteria->alias='post';

$params=array();
$result=Post::model()->findAll($criteria,$params);

creates this select
SELECT title, content FROM `tbl_post` `post` WHERE `post`.`title` LIKE '%test%'


but this doesn't work (relation added)
$criteria=new CDbCriteria;
$criteria->condition=("`post`.`title` LIKE '%test%'");
$criteria->select =array('title','content');
$criteria->alias='post';

$params=array();
$result=Post::model()->with('author')->findAll($criteria,$params);

creates this select: (alias setting is ignored)
SELECT `t`.`title` AS `t0_c1`, `t`.`content` AS `t0_c2`, `t`.`id` AS `t0_c0`, `author`.`id` AS `t1_c0`, `author`.`username` AS `t1_c1`, `author`.`password` AS `t1_c2`, `author`.`salt` AS `t1_c3`, `author`.`email` AS `t1_c4`, `author`.`profile` AS `t1_c5` FROM `tbl_post` `t`  LEFT OUTER JOIN `tbl_user` `author` ON (`t`.`author_id`=`author`.`id`) WHERE (`post`.`title` LIKE '%test%')


of cause this would work:
$criteria=new CDbCriteria;
$criteria->condition=("`t`.`title` LIKE '%test%'");
$criteria->select =array('title','content');

$params=array();
$result=Post::model()->with('author')->findAll($criteria,$params);


This is just for showing a problem and is not code i use. I have several classes for query generation in ajax calls and export function which have the old 'tablename' as sort or search function and I really would like to make it work again without changing every name to 't.'

Also I find the readability isn't as good as before.

regards Horizons
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,308
  • Joined: 17-January 09
  • Location:Russia

Posted 12 January 2010 - 07:48 AM

There were reasons to do it:
http://code.google.c...s/detail?id=796
http://code.google.c...s/detail?id=817

And a new proposal that will solve your problem:
http://code.google.c...s/detail?id=818
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   horizons 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 18-December 08

Posted 12 January 2010 - 08:28 AM

View Postsamdark, on 12 January 2010 - 07:48 AM, said:

There were reasons to do it:
http://code.google.c...s/detail?id=796
http://code.google.c...s/detail?id=817

And a new proposal that will solve your problem:
http://code.google.c...s/detail?id=818


the proposal doesn't work see demo above (used the lastest blog demo)
with
$criteria=new CDbCriteria;
$criteria->condition=("`post`.`title` LIKE '%test%'");
$criteria->select =array('title','content');

$params=array();
$result=Post::model()->with('author')->findAll($criteria,$params);

also added
function alias(){
return "post";
}
to the post model still doesn't work when relations are used.


regards Horizons
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,308
  • Joined: 17-January 09
  • Location:Russia

Posted 12 January 2010 - 08:47 AM

It's a proposal, so it's not yet implemented or even scheduled to be implemented.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
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