Monday, September 6, 2010

Re: Problems with two hasOne-relationed models: no vice versa

The pair to hasOne is belongsTo.

On Sep 7, 4:08 am, DerBjörn <b.unkh...@googlemail.com> wrote:
> Hi,
>
> i have 2 models that are connected between each other with hasOnes:
>
> - ModelA
>
> var $hasOne = array(
>      'ModelsB' => array(
>      'classname' => 'ModelsB',
>      'foreignKey' => modelA_id,
> ...
>
> - ModelB
>
> var $hasOne = array(
>      'ModelsA' => array(
>      'classname' => 'ModelsA',
>      'foreignKey' => id,
> ...
>
> If i now make a read($id, null) in modelA_controller i get an array
> with the data of modelA and the data of its modelB. Looks correct.
> But vice versa it doesn't work: I get the data of modelB, but not of
> its modelA, but data of a modelA with the same id as modelB has.
> The query explains why: ... LEFT JOIN modelA AS modelsA ON (ModelA.id
> = ModelB.id) ...
> I have to change something in the hasOne-Relation of ModelB? But why
> it works then in one direction?
>
> Thanks for your help :)

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate