Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8273949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:36:19+00:00 2026-06-08T07:36:19+00:00

I am having very difficult time to select usernames of all posts in the

  • 0

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->select='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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:36:20+00:00Added an answer on June 8, 2026 at 7:36 am

    what with does is eager loading..that means the relation’s data
    will also loaded from database alongwith, and when when u’ll call the
    relation, there won’t be a actual query..

    What select does is it selects it from database and maps it to model
    variable..

    Now in your case what is happening is you’re trying to write some relation’s column in select, which will be there in select even without writing it, but as there is no corresponding variable to map this value yii is throwing an error..

    So first thing if you need to username of auther in response, you can get it by relation calling, which won’t be a database call, and u dont need to write a select..

    And if u want to call the username as a part of the post model only u have got to declare it as a property in model, and then specify alias in select..

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

    and in your Post model declare..

    public $auther_username;
    

    Now it won’t throw error, and you can access the username by both ways..$post->auther_username, and $post->auther->username

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MYSQL Server version: 5.5.16 and having a very difficult time establishing
I am having a very difficult time handling null returns in DB2. I've tried
I am having a very difficult time setting up a binding which I think
I have been having a very difficult time editing my .htaccess file to do
I'm trying to learn LINQ to SQL but having a very difficult time. I
I'm having a very difficult time trying to figure out how to make my
I'm having a very difficult time debugging a problem with an application I've been
I'm having a difficult time getting answers to a few very basic PHP questions.
So, I am having a very difficult time explaining my problem, I hope this
I'm having a very difficult time understanding how a c# form can populate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.