On Aug 22, 2:34 pm, xephex <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I got a ModelA that hasOne ModelB.
> They aren't suppost like
> ModelB.foreignKey = ModelA.id
> as I need
> ModelB.foreignkey = ModelA.otherField
>
> I tried
> class ModelA {
> var $hasOne = array('ModelB'=>array('conditions' => 'ModelB.foreignKey
> = ModelA.otherField'));}
>
> This doesn't work because Cake produces:
> ON (`ModelB`.`foreignKey` = `ModelA`.`otherField` AND
> `ModelB`.`foreignKey` = `ModelA`.`id`)
>
> I read DboSource::generateAssociationQuery() line 1094 and I know now
> that I need something like:
> class ModelA {
> var $hasOne = array('ModelB'=>array('conditions' =>
> array('ModelB.foreignKey' => 'ModelA.otherField'));}
>
> This of course doesn't work because 'ModelA.otherField' is treated as
> a string and not as a field, which would be what I need.
>
> So it comes down to this: How do I write ´fieldA´ = ´fieldB´ in a
> condition using an array and not a string?

Whether it helps in the end is another matter, but the answer is..

var $hasOne = array('ModelB'=>array('conditions' =>
array('ModelB.foreignKey' => '´ModelA´.´otherField´'));

hth,

AD


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to