??.createTime in my SQL. Why?

Hi,

I’ve been away from yii for a while and have just resurrected some old projects, and have plugged them into 1.1.4.

I immediately tripped over the ‘t’ issue noted here: http://code.google.com/p/yii/issues/detail?id=796 quite a lot.

I really should know better than commenting, but this is a daft solution to the problem. But I guess it’s there now, so I have to fix tons of stuff. w00t!

Anyway, I now get the following error:


CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

for the right syntax to use near '??.createTime' at line 1

Here’s the SQL that’s generated:


SELECT `comments`.`id` AS `t1_c0`, `comments`.`content` AS `t1_c1`, `comments`.`contentDisplay`

AS `t1_c2`, `comments`.`status` AS `t1_c3`, `comments`.`createTime` AS `t1_c4`, `comments`.`author`

AS `t1_c5`, `comments`.`email` AS `t1_c6`, `comments`.`url` AS `t1_c7`, `comments`.`postId`

AS `t1_c8` FROM `Comment` `comments`  WHERE (`comments`.`postId`=:ypl0) ORDER BY ??.createTime

which, from the stack trace:


#6 /home/marc/public_html/yii_blog/protected/controllers/PostController.php(60): CActiveRecord->__get('comments')

is generated by:


00060:         $this->render('show', array('post' => $post, 'comments' => $post->comments,    'newComment' => $comment));

Why? What has changed to make this happen?

Thanks.

Sorry for the line overflows. I fixed them in the preview, but that’s clearly broken as it doesn’t match what happens when you post. Where do I file the bug? :)

In 1.1, actual relation names are used as aliases (‘t’ is alias for the primary).

/Tommy

Cheers, I think I tracked down that the behaviour of relations() has changed. So, I have:


'comments' => array(self::HAS_MANY, 'Comment', 'postId', 'order'=>'??.createTime'),

which is no longer valid. Not sure yet what the correct syntax is. Is there a generic change I can make to these statements to "upgrade" them?

Okay, got it now, I think. Not at all convinced by the ‘t’-thing and how it propagates to controllers. That’s code obfuscation, which is one of the deadly sins, imo. The docs need to far better explain what’s going on here. I went over to the Rails docs to remind myself of expected scopes’ behaviour.