Thanks, Im also trying to do it that way but in the ProfileTable because I need to retrieve many records at once so I need a join so that there will be no query for each and I can do it fine but then the result set cannot use functions defined on the model anymore (because it's raw sql)

Does anyone have a better implentation for this? : /

I was thinking of something similar to PHP-Activerecord where you can even do joins on a db without any schema by just specifying the table name on the join and it will return model objects just fine and would just put info from the unrelated table as a flat array..

I know that I may have to bypass the ORM if the table is not in the schema but I think doctrine would be flexible enough : )


---------- Forwarded message ----------
From: Pierre-Yves LEBECQ <[email protected]>
Date: Oct 12, 10:18 pm
Subject: Doctrine JOIN model defined in schema with and one that isnt
To: symfony users


I would go in a very simple way :

In your model class Profile, you could add a method which retrieves the PDO
connection from doctrine and query the user table directly. It could look
like this :

class Profile extends BaseProfile
{
  public function getUser()
  {
    $dbh =
Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
    $stmt = $dbh->prepare("SELECT * FROM user WHERE id = ?");
    if ($stmt->execute(array($this->getId())))
    {
      return new ArrayObject($stmt->fetch(PDO::FETCH_ASSOC));
    }
    return null;
  }

}

And then you could use it this way :

$profile->getUser()->id;
$profile->getUser()->user_id;
$profile->getUser()->field1;

But there's maybe a better way to do this.

I didn't try it so maybe there are some mistakes in the code but it could be
a starting point. Careful, if you iterate over a Doctrine_Collection of
Profile, each call to getUser() will execute a query to the database.

But anyway, I'm also waiting for other ideas, I'm also interessed in this
topic.

2010/10/12 <[email protected]>

>  Hello guys, given that:

> profile <--- defined in schema (ofc used by symfony)
> id
> user_id
> field1
> field2

> user <--- not in schema, because this is a table used by another script (a
> forum script for example)
> id
> field1
> field2

> I would like to get all profiles and their corresponding users.
> I don't need the retrieved data from the user table to be an object and I
> think that's also not possible since it's not defined in the schema. so a
> flat array would be okay.

> Something like $profile->user['id] I think would happen instead of the
> regular $profile->getUser()->getId() on related tables because they are
> unrelated?

> In any case, how I do this in Doctrine? Thanks : )

> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com

> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-users%[email protected]>
> For more options, visit this group at
>http://groups.google.com/group/symfony-users?hl=en

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to