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 5991343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:22:23+00:00 2026-05-22T23:22:23+00:00

After working hard in my ZF/Doctrine integration I’m having a problem translating my previous

  • 0

After working hard in my ZF/Doctrine integration I’m having a problem “translating” my previous Zend_Db work into Doctrine. I used generate-models-db to create the models and I did got to access some properties form the view but only those concerning the table whose model I created like this:

$usuarios = new Model_Users();
$usr = $usuarios->getTable()->findAll();
$this->view->show = $usr;

Model_Users is related to two tables with this method:

public function setUp()
{
    parent::setUp();
    $this->hasMany('Model_PlanillaUsers as PlanillaUsers', array(
         'local' => 'id',
         'foreign' => 'users_id'));

    $this->hasMany('Model_UsersHasPais as UsersHasPais', array(
         'local' => 'id',
         'foreign' => 'users_id'));
}

Right now I’m concerned about UsersHasPais…which tells me what pais.pais fields and which users.id entries match. This is the Model_Pais:

abstract class Model_Base_Pais extends Doctrine_Record
{
public function setTableDefinition()
{
    $this->setTableName('pais');
    $this->hasColumn('id', 'integer', 4, array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => true,
         'autoincrement' => true,
         ));
    $this->hasColumn('pais', 'string', 20, array(
         'type' => 'string',
         'length' => 20,
         'fixed' => false,
         'unsigned' => false,
         'primary' => false,
         'notnull' => true,
         'autoincrement' => false,
         ));
}

public function setUp()
{
    parent::setUp();
    $this->hasMany('Model_UsersHasPais as UsersHasPais', array(
         'local' => 'id',
         'foreign' => 'pais_id'));
}
}

And this is the join table:

abstract class Model_Base_UsersHasPais extends Doctrine_Record
{
public function setTableDefinition()
{
    $this->setTableName('users_has_pais');
    $this->hasColumn('id', 'integer', 4, array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => true,
         'autoincrement' => true,
         ));
    $this->hasColumn('users_id', 'integer', 4, array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => false,
         'notnull' => true,
         'autoincrement' => false,
         ));
    $this->hasColumn('pais_id', 'integer', 4, array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => false,
         'notnull' => true,
         'autoincrement' => false,
         ));
}

public function setUp()
{
    parent::setUp();
    $this->hasOne('Model_Users as Users', array(
         'local' => 'users_id',
         'foreign' => 'id'));

    $this->hasOne('Model_Pais as Pais', array(
         'local' => 'pais_id',
         'foreign' => 'id'));
}
}

Now what I want to be able to retrieve,…if not clear enough is the fields called pais from the pais table that match with my current user id. How do I do this with Doctrine?

EDIT:

//Added to Model_Users class


public function saveUser($user) {
    $this->email = $user['email'];
    $this->password = crypt($user['password'], $this->_salt);
    $this->url = $user['url'];
    $this->responsable = $user['responsable'];
    $this->role = $user['role'];
    $this->fecha = Zend_Date::now()->toString('yyyyMMddHHmmss');
    $id = $this->save();
}


//Users table schema
Users:
  connection: 0
  tableName: users
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    email:
      type: string(50)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    password:
      type: string(250)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    url:
      type: string(50)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    responsable:
      type: string(50)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    role:
      type: string(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    fecha:
      type: timestamp(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    PlanillaUsers:
      local: id
      foreign: users_id
      type: many
    UsersHasPais:
      local: id
      foreign: users_id
      type: many
  • 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-22T23:22:24+00:00Added an answer on May 22, 2026 at 11:22 pm

    In your controller write a query something like

      $cu = current_user_id // you'll have to set this your self from a session variable etc
      $q = Doctrine_Query::create()
           ->select('p.pais')   
           ->from('Model_Pais p')
           ->leftJoin('p.Model_UsersHasPais s')
           ->leftJoin('s.Model_Users u')
            ->where('u.id = ?',$cu); 
        $result = $q->fetchArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am back into c/Linux. The question might look stupid, but relevant after working
I'm having a hard time refilling the stack after i take it all off
It is hard to put this problem into words, but a real world example
I'm really trying hard to understand this new concept after working so long with
So after a lot of hard (and fun) work in development I’ve finally gotten
I'd been working on something, and decided it was completely screwed...after having committed some
After working for a while developing games, I've been exposed to both variable frame
After working with .NET's HttpWebRequest / Response objects, I'd rather shoot myself than use
After working in Eclipse for the past 3 years and memorizing all of the
After working with ASP.Net MVC, it has me thinking about Rails. I worked with

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.