I guess one-to-one in this case isn't the correct description.

sfGuardUser has one Company, Company has man sfGuardUser. To
accomplish this (because I shouldn't edit the sfGuardUser model
directly) I go through an intermediary table sfGuardUserProfile. I
believe my schema above is correct, and the refClass is generated
because I am using the intermediary table and I can't eliminated it as
it is in the base model.

On Oct 22, 4:50 pm, Stéphane <[email protected]> wrote:
> Hi,
>
> You don't need refClass for 1-to-1 !
>
> Cheers,
>
> Before Printing, Think about Your Environmental Responsibility!
> Avant d'Imprimer, Pensez à Votre Responsabilitée Environnementale!
>
>
>
>
>
>
>
> On Sat, Oct 23, 2010 at 1:31 AM, Jonotron <[email protected]> wrote:
> > I want to create a one-to-one relationship between users and
> > companies. Since I shouldn't be editing the sfDoctrineGuard schema's
> > directlyI've created a sfGuardUserProfile model:
>
> > sfGuardUserProfile:
> >  tableName:            sf_guard_user_profile
> >  columns:
> >    user_id:            { type: integer, notnull: true }
> >    org_id:             { type: integer, notnull: true }
> >  relations:
> >    sfGuardUser:        { onDelete: CASCADE, local: user_id, foreign:
> > id, foreignAlias: Profile, foreignType: one, type: one }
> >    Company:        { onDelete: CASCADE, local: org_id, foreign: id,
> > foreignAlias: sfGuardUserProfiles }
>
> > And my Company model has a relation like this:
> >  relations:
> >    sfGuardUser:
> >      foreignAlias: Company
> >      class: sfGuardUser
> >      local: id
> >      foreign: org_id
> >      refClass: sfGuardUserProfile
> >      foreignType: one
>
> > This appears to create all the correct models, the basesfGuardUser
> > model has:
>
> >        $this->hasOne('Company', array(
> >             'refClass' => 'sfGuardUserProfile',
> >             'local' => 'org_id',
> >             'foreign' => 'id'));
>
> > However, when I do:
> > $sf_user->getGuardUser()->getCompany();
>
> > it returns a collection rather than an object. The simple fix is to do
> > this:
> > $sf_user->getGuardUser()->getProfile()->getCompany();
>
> > (and refactor it into the sfGuardUser class)
>
> > I suspect that the refClass is what is causing this behaviour. Is this
> > intended? is there another way to create a one-to-one relationship as
> > I've described above? My solution works, but it feels wrong somehow.
>
> > 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]
> > 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