trying to do
$dataProvider=new CActiveDataProvider('BlogPosts', array(
CDbCommand failed to execute the SQL statement: SQLSTATE: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous. The SQL statement executed was: SELECT `t`.`id` AS `t0_c0`, `t`.`creationDate` AS `t0_c1`, `t`.`lastUpdate` AS `t0_c2`, `t`.`authorID` AS `t0_c3`, `t`.`comments` AS `t0_c4`, `t`.`title` AS `t0_c5`, `t`.`body` AS `t0_c6`, `t`.`tags` AS `t0_c7`, `author`.`id` AS `t1_c0`, `author`.`authKey` AS `t1_c1`, `author`.`registrationTime` AS `t1_c2`, `author`.`lastLoginTime` AS `t1_c3`, `author`.`ip` AS `t1_c4`, `author`.`userAgent` AS `t1_c5`, `author`.`username` AS `t1_c6`, `author`.`password` AS `t1_c7`, `author`.`email` AS `t1_c8`, `author`.`role` AS `t1_c9`, `author`.`ban` AS `t1_c10` FROM `tbl_blog_posts` `t` LEFT OUTER JOIN `tbl_users` `author` ON (`t`.`id`=`author`.`id`) WHERE (authorID=1) ORDER BY id DESC LIMIT 10
if i replace
id DESC to t.id DESC, it works… but what im doint wrong?
public function relations()
'posts'=>array(self::HAS_MANY, 'BlogPosts', 'authorID'),
in blog posts
'author' => array(self::BELONGS_TO, 'User', 'id'),
You are not doing anything wrong.
That’s how SQL works.
If you are querying two tables with rows with the same name, one of them needs an alias.
But Yii should do it authomaticly, not ?
I’m using active record so its strange…
I guess it’s due to performance and consistency.
What ‘id’ do you mean?
author.id or post.id?
as you can see in the first code box, I trying to get all posts, and the author, the order should be by blog posts…
actually I don’t need full user, just need the username… event don’t need the id… just don’t know how to get for now… searching …
'with'=>'author' => array('select' => array('username')),
Haven’t really checked if you can do this, but why not?
But if your model already has the relation ‘user’, then you can just use lazy loading and leave out the ‘with’.
Actually I’m doing the relation stuff for FW learning porpuses…
I don’t think that it is smart to laod author name, by a foreign key…
better practice would be just save id and username in the Posts table, not?
No, don’t do that!
What do you need a relational database for if it wasn’t for it’s relational properties??
If you have a relation called ‘author’ in your ‘post’ model, you can access 'author’s username like ‘post->author->username’.
That’s exactly how you should use it.
Storing the username in the post table is just duplication of data.
Use a foreign key and store author_id in the post table instead. And let Yii work it’s magic.
If you use ‘select’ in your queries, then you are not going to pull in the whole author table, only what fields you need (if you have a performance issue).
I really don’t know if I’m in the right direction…
I turned off eaccelerator, and my script consume 13.5mb of memory for now…
What I have? nothing! just 12 posts, and CListView
After i trun eaccelerator, it consume 2.5mb…
With cache of course I will cut it by 1mb to 1.5mb for now…
But this is really scary… I don’t know… maybe I’m just lazy? just give up AR ?
I think one ddos on the sample blog will kill my server
Yii is pretty lean, believe me.
The usage is not going to skyrocket, it will stay pretty much as-is on your server now, also when you’ve got loads of records.
It’s not a linear resource hog.
Solved problems… forgot about scheme cache… cause a lot of problems
Have a question… to see what im using see post № 1…
The problem is - I want to get only the username via foreign key…
But AR of BlogPosts, loads entire User with all fields…
Is there a way to load only part of User ? or User is a object, so I can’t load just part of it?