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

  • SEARCH
  • Home
  • 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 6074095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:20:38+00:00 2026-05-23T10:20:38+00:00

table: USERS | id | name | city_id | | 1 | jonh |

  • 0
table: USERS
| id | name | city_id |
| 1  | jonh |  1      |
table: CITY
| id | city_ name |
| 1  | London |

in action.class:

$this->user_list = Doctrine::getTable('Users')
      ->createQuery('a')
      ->execute();

and this generate:

$user_lists->getId();
$user_lists->getName();
$user_lists->getCityId();


| 1 | john | 1 |

how can i make:

| 1 | jonh | London |

?

i make in UsersTableClass:

public function getCityName($id) {

        $q = $this->createQuery('j')
        ->select('u.name, c.city_name')
        ->from('Users u')
        ->where('city_id = ?', $id)
        ->leftJoin('u.city c');

        return $q->fetchOne();   
}


$user_lists->getId();
$city_name;
$user_lists->getCityId();

and in action.class:

$this->user_list = Doctrine::getTable('Users')
      ->createQuery('a')
      ->execute();
$this->city_name = Doctrine::getTable('Users')->getCityName($this->user_list->getCityId());

then i have error:

Fatal error: Call to undefined method
Doctrine_Collection::getCityId()

  • 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-05-23T10:20:39+00:00Added an answer on May 23, 2026 at 10:20 am

    The reason you get the error is because you are calling getCityId() on the collection class: the query you execute (SELECT * FROM users....) returns multiple users, so it is a collection. You have to loop through the results to get the invidual results. If you expect a query to return only one result you can use fetchOne() instead of execute() on your query.

    You can reference related records just by their relation name.

    $this->user_list = Doctrine::getTable('Users')
          ->createQuery('u')
          ->leftJoin('u.City');  // <-- Added for performance
          ->execute();
    
    foreach($this->user_list as $user) {
      $id = $user->id;                // is the same as $user->getId()
      $name = $user->name;            // == $user->getName(); 
      $cityName = $user->City->name;  // == $user->getCity()->getName();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView binded to this table: [Users] ID Name -- ---- 11
I have table with 50 entries (users with such details like Name Surname Location
My table structure looks like this: tbl.users tbl.issues +--------+-----------+ +---------+------------+-----------+ | userid | real_name
Lets say I have a table with columns such as: ID Name City State
Im trying to join a user table to retrieve the users login name. I
Let's put an easy example with two tables: USERS (Id, Name, City) PLAYERS (Id_Player,
I need a simple table with a user name and password field in MySQL.
DDL for Database Tables: Users: id - int - identity name - varchar -
I have a table of users which has a username column consisting of a
Which Database table Schema is more efficient and why? Users (UserID, UserName, CompamyId) Companies

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.