OK, so I think I found a workaround:
I created a second model (identical to the Merchants model) called
RelatedMerchants (setting $useTable to 'merchants'). This then allows
you to use the code:
var $hasAndBelongsToMany =
array('RelatedMerchant'=>array('classname'=>'Merchant',
'joinTable'=>'related_merchants',
'foreignKey'=>'merchant1_id',
'associationForeignKey'=>'merchant2_id'));
and the related merchants appear in their own array when the model
data is loaded.
On Aug 10, 4:14 pm, David <[EMAIL PROTECTED]> wrote:
> Hmm - no suggestions? Or maybe I should have chosen a different title
> for this thread...
>
> I realised that the problem is exacerbated when you use forms to add/
> change data - the html helper doesn't seem to support strings like
> 'Merchant/0/id', and 'Merchant/id' is of course ambiguous - does it
> refer to the current merchant or one of the related merchants? (I'm
> using 1.1 btw).
>
> Surely someone has run into this problem before?
>
> On Aug 9, 5:46 pm, David <[EMAIL PROTECTED]> wrote:
>
> > Hi guys,
>
> > Yep, another HABTM question I'm afraid... but I haven't been able to
> > find the answer to this one on the group, so maybe it hasn't been
> > brought up yet :)
>
> > My app contains a model merchants, each of which hasAndBelongsToMany
> > related merchants. No problem, I just use this code in the merchant
> > model:
>
> > var $hasAndBelongsToMany =
> > array('Merchant'=>array('classname'=>'Merchant',
> > 'joinTable'=>'related_merchants', 'foreignKey'=>'merchant1_id',
> > 'associationForeignKey'=>'merchant2_id'));
>
> > The problem comes when the data is retrieved from the DB. Imagine
> > 'merchants' had a conventional HABTM relationship with 'customers'. we
> > would have:
>
> > $data['Merchant'] (containing the data about the merchant)
> > $data['Customer'] (containing an array of the associated customers)
>
> > However, with the related merchants their information is put inside
> > the $data['Merchant'] array! So we have
>
> > $data['Merchant']['id'] (id of the merchant)
> > $data['Merchant']['name'] (name of the merchant)
> > $data['Merchant'][0] (array containing the info for the first related
> > merchant)
> > $data['Merchant'][1] (array containing the info for the second related
> > merchant)
> > etc.
>
> > I think this is messy and would prefer to have something like:
>
> > $data['Merchant'] (containing the data about the merchant)
> > $data['RelatedMerchant'] (containing an array of the related
> > merchants)
>
> > Does anyone know how to do this?
>
> > Thanks!
>
> > David
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---