A: 

Before $p->save();, have $p->users_id = $u->id.

Also, why are you calling the table User*s* (plural)? That's just going to make code very confusing.

Also again, if you have separate tables to hold different info about the user (a User and a user's Profile) because you saw it in sfGuardPlugin, PLEASE DO NOT DO THIS! It is a ridiculous idea that will only make you regret it later. I don't know what the Symfony/Doctrine team were drinking when they thought of that idea...

Coronatus
Kind of worked... The error disappeared, but the users_id column in the profile table has a value of 0 not the value of users.id. As for your other suggestions, the code is actually based on the ion_auth library for codeigniter. The table is called users cos I haven't got around to changing it. I've separated out the data to keep data needed for auth separate from general data about the user.
musoNic80
Isn't storing the profile in a separate table just basic database normalization? Why is it ridiculous?
i-g
+1  A: 

Hi.

There are a number of ways to skin this cat. I have created a simplified example based loosely on what I can gather from your question.

Firstly, here is the YAML that I use to generate for my one-to-one model classes:

Identity:
  columns:
    username: string(50)
    password: string(50)
    email: string(50)

Profile:
  columns:
    identity_id: integer(10)
    firstname: string(50)
    lastname: string(50)
  relations:
    Identity:
      foreignType: one

Now in PHP I can create a new Identity (or User in your case) and add related Profile data by simply:

        $identity = new Identity();
        $identity->username = 'james';
        $identity->password = 'secret';
        $identity->email = '[email protected]';
        //now adding the related data
        $identity->Profile->firstname = 'james';
        $identity->Profile->lastname = 'bond';
        $identity->save();

Hopefully this example will help you a bit.

edit:

here are the generated classes from the YAML in case that also helps:

BaseIdentity.php

<?php
abstract class BaseIdentity extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('identity');
        $this->hasColumn('username', 'string', 50, array(
             'type' => 'string',
             'length' => '50',
             ));
        $this->hasColumn('password', 'string', 50, array(
             'type' => 'string',
             'length' => '50',
             ));
        $this->hasColumn('email', 'string', 50, array(
             'type' => 'string',
             'length' => '50',
             ));
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Profile', array(
             'local' => 'id',
             'foreign' => 'identity_id'));
    }
}

BaseProfile.php

<?php

abstract class BaseProfile extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('profile');
        $this->hasColumn('identity_id', 'integer', 10, array(
             'type' => 'integer',
             'length' => '10',
             ));
        $this->hasColumn('firstname', 'string', 50, array(
             'type' => 'string',
             'length' => '50',
             ));
        $this->hasColumn('lastname', 'string', 50, array(
             'type' => 'string',
             'length' => '50',
             ));
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Identity', array(
             'local' => 'identity_id',
             'foreign' => 'id'));
    }
}
So Over It
Just tried it and I'm still getting the same error...
musoNic80
It should. I'll have to go through your code a bit closer and see what else is happening. Could you pop up the YAML for your models? - it is a little easier to work through than the actual PHP generated classes
So Over It
I'll have a go! I've never generated a YAML file before. Is there an easy way to do it? Also, I'm away from my computer at the mo, so there might be a delay!
musoNic80
I'm having permission problems when trying to convert my models to yaml with Doctrine. I'm assuming Doctrine will be trying to save the new file in the web root so I don't understand why it's not allowed to!
musoNic80