Thank you for the reply,
I already use Containable but can't limit the BreedConnection array
since it's the join table and not associated to the Model that gets
the data.
This is the way I find the data. Does not work with recursive lower
than 1.
$test=$this->RaseCaini->find('first',array
('recursive'=>1,'fields'=>array('id'),'conditions'=>array
('id'=>11),'contain'=>array('User')));
This is the model HABTM relation:
var $hasAndBelongsToMany = array(
'User' => array(
'className' => 'User',
'joinTable' => 'breed_connections',
'associationForeignKey' => 'target_id',
'foreignKey' => 'rasa_id',
'conditions'=>array('type'=>1),
'fields'=>array('id'),
'dependent'=> false
)
);
Thank you,
Claudiu
On Jul 12, 4:37 pm, Nancy <[email protected]> wrote:
> I think that's fine it is using a little too recursive for what you
> want. You can set recursive to -1 to only get the User table. It's
> an option you can put in your query or you can set it like this:
> $this->Model->recursive = -1
>
> There's also a 'behavior' called "Containable" that lets you determine
> which tables you want because sometimes you just don't want the
> default behavior.
>
> Here's an example of a containable query from my project:
>
> function getCalcParamsByDgid($id, $deviceId)
> {
> $this->Behaviors->attach('Containable');
> $got = $this->find('first', array(
> 'contain' => array(
> 'Calcparam' => array(
> 'Calcparamvalue' => array(
> 'Unit',
> 'conditions' => array(
> 'Calcparamvalue.device_id' =>
> $deviceId)
> ),
> 'Unit',
> ),
> ),
> 'conditions' => array(
> 'id' => $id,
> ),
> ));
> return ($got);
> }
>
> On Jul 12, 4:30 am, Claudiu Apetrei <[email protected]> wrote:
>
> > Hello,
>
> > I am trying to get the hasAndBelongsToMany assosciations to work but I
> > just can't get it to return the data right. It always returns the
> > joinTable fields for each relation.
>
> > I have a table BreedConnections and want to get the associated users,
> > I get the user array right but also get in that array the jointable
> > fields. Everything works ok but it's not really good since it doubles
> > the amount.
>
> > This is how it looks for each user :
>
> > [User] => Array
> > (
> > [0] => Array
> > (
> > [id] => 1
> > [avatar] => claudiu_apetrei_1
> > [avatar_type] => .jpg
> > [nume] => Apetrei
> > [prenume] => Claudiu
> > [BreedConnection] => Array
> > (
> > [id] => 11
> > [rasa_id] => 11
> > [rasa_nume] => Ciobanesc german
> > [rasa_url] => ciobanesc-german
> > [type] => 1
> > [target_id] => 1
> > [data] => 0000-00-00 00:00:00
> > [auto_remove] => 1
> > )
>
> > )
>
> > )
>
> > Is this how it's supposed to return or am I doing something wrong ?
>
> > Thank You,
> > Claudiu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---