Yii Framework Forum: Yii cdbcriteria select a relation's columns - Yii Framework Forum

Jump to content

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

Yii cdbcriteria select a relation's columns Yii cdbcriteria select a relation's columns Rate Topic: -----

#1 User is offline   rajat_27 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 03-January 12

Posted 19 February 2012 - 09:52 AM

I am having very difficult time to select usernames of all posts in the blog demo given in Yii..

author is relation of post class with user...

$criteria = new CDbCriteria;
$criteria->with='author';
$criteria->distinct=true;
$criteria->select='author_id,author.username';
$dataProvider=new CActiveDataProvider('Post', array(
'criteria' => $criteria,
));
var_dump($dataProvider->getData());

Error:
Active record "Post" is trying to select an invalid column "author.username". Note, the column must exist in the table or be an expression with alias.

Please plese someone help me..its urgent..
0

#2 User is offline   Aigor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 26-January 11

Posted 02 March 2012 - 07:32 AM

View Postrajat_27, on 19 February 2012 - 09:52 AM, said:

I am having very difficult time to select usernames of all posts in the blog demo given in Yii..

author is relation of post class with user...

$criteria = new CDbCriteria;
$criteria->with='author';
$criteria->distinct=true;
$criteria->select='author_id,author.username';
$dataProvider=new CActiveDataProvider('Post', array(
'criteria' => $criteria,
));
var_dump($dataProvider->getData());

Error:
Active record "Post" is trying to select an invalid column "author.username". Note, the column must exist in the table or be an expression with alias.

Please plese someone help me..its urgent..


I had same problem,
look here Select problem CDbCriteria with join and select
I think correct is
$criteria->with = array("author"=>array("select"=>"id,username"));
2

#3 User is offline   Clem 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 15-November 10

Posted 11 November 2012 - 05:42 AM

View PostAigor, on 02 March 2012 - 07:32 AM, said:

I think correct is
$criteria->with = array("author"=>array("select"=>"id,username"));

Thanks! You save me a lot of time!!!
0

#4 User is offline   dmapes123 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-December 10

Posted 22 April 2014 - 10:45 AM

total life saver!!!!! Thanks!
Duncan Mapes
Challenge Media Group LLC
ideas@challengemediagroup.com | http://www.challengemediagroup.com
Twitter: http://twitter.com/duncanmapes | LinkedIn: http://linkedin.com/in/duncanmapes
0

#5 User is offline   arunkumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 03-July 12

Posted 02 September 2014 - 05:58 AM

View PostAigor, on 02 March 2012 - 07:32 AM, said:

I had same problem,
look here Select problem CDbCriteria with join and select
I think correct is
$criteria->with = array("author"=>array("select"=>"id,username"));


Helpful.. thanks
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