Re: HABTM round trip query

2013-02-10 Thread lowpass
I forgot the Language model to get the *other* langs the artist uses.

public function getArtistsForLang($lang)
{
return $this->find(
'all',
array(
'conditions' => array(
$this->alias.'.code' => $lang
),
'contain' => array(
'Artist' => array(
'ArtistsLanguage' => array(
'Language'
)
)
)
)
);
}

On Sun, Feb 10, 2013 at 8:53 PM, lowpass  wrote:
> Try this. I'm assuming your languages table has a 'code' column and
> the request passes a 2-letter string for the code for the desired
> language. That's probably how I'd do it but you may need to modify for
> your own setup.
>
> (This would be in the Language model.)
>
> public function getArtistsForLang($lang)
> {
> return $this->find(
> 'all',
> array(
> 'conditions' => array(
> $this->alias.'.code' => $lang
> ),
> 'contain' => array(
> 'Artist' => array(
> 'ArtistsLanguage'
> )
> )
> )
> );
> }
>
> This could be improved by specifying joins to reduce the number of queries.
>
> On Sun, Feb 10, 2013 at 7:25 AM, crouch...@googlemail.com
>  wrote:
>> Hi all,
>>
>> If this topic is covered, sorry, but I don't really know what to search
>> under and all my searches resulted in nothing.
>>
>> Background:
>> Developing a site for a voice over company.
>>
>> Requirement:
>> Voice artists can have several different languages and languages can have
>> several different voice artists, each artist can have a playable recording
>> for each language.
>>
>> What am I doing:
>> Searching for all artists that can speak a given language, but want to know
>> what languages they also speak.
>>
>> Basic search:
>> $this->Language->find('all');
>>
>> Result
>> Language->Artist->ArtistsLanguage<-- Only the record to the language is
>> resulting.
>>
>> Desire
>> Language->Artist->Language->array(record 1->ArtistsLanguage, record
>> 2->ArtistsLanguage, etc...)
>>
>> Comments:
>> Basically, I am looking to find all artists for a given language. This part
>> works, but the result for the list of languages that the artists speaks only
>> results in the HABTM model record belonging to the artist.
>>
>> How can a do a round trip in a HABTM relationship?
>>
>> Thanks for all the help,
>> Jay
>> Result:
>>
>> --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cake-php+unsubscr...@googlegroups.com.
>> To post to this group, send email to cake-php@googlegroups.com.
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: HABTM round trip query

2013-02-10 Thread lowpass
Try this. I'm assuming your languages table has a 'code' column and
the request passes a 2-letter string for the code for the desired
language. That's probably how I'd do it but you may need to modify for
your own setup.

(This would be in the Language model.)

public function getArtistsForLang($lang)
{
return $this->find(
'all',
array(
'conditions' => array(
$this->alias.'.code' => $lang
),
'contain' => array(
'Artist' => array(
'ArtistsLanguage'
)
)
)
);
}

This could be improved by specifying joins to reduce the number of queries.

On Sun, Feb 10, 2013 at 7:25 AM, crouch...@googlemail.com
 wrote:
> Hi all,
>
> If this topic is covered, sorry, but I don't really know what to search
> under and all my searches resulted in nothing.
>
> Background:
> Developing a site for a voice over company.
>
> Requirement:
> Voice artists can have several different languages and languages can have
> several different voice artists, each artist can have a playable recording
> for each language.
>
> What am I doing:
> Searching for all artists that can speak a given language, but want to know
> what languages they also speak.
>
> Basic search:
> $this->Language->find('all');
>
> Result
> Language->Artist->ArtistsLanguage<-- Only the record to the language is
> resulting.
>
> Desire
> Language->Artist->Language->array(record 1->ArtistsLanguage, record
> 2->ArtistsLanguage, etc...)
>
> Comments:
> Basically, I am looking to find all artists for a given language. This part
> works, but the result for the list of languages that the artists speaks only
> results in the HABTM model record belonging to the artist.
>
> How can a do a round trip in a HABTM relationship?
>
> Thanks for all the help,
> Jay
> Result:
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




HABTM round trip query

2013-02-10 Thread crouch...@googlemail.com
Hi all,

If this topic is covered, sorry, but I don't really know what to search 
under and all my searches resulted in nothing.

Background:
Developing a site for a voice over company.

Requirement:
Voice artists can have several different languages and languages can have 
several different voice artists, each artist can have a playable recording 
for each language.

What am I doing:
Searching for all artists that can speak a given language, but want to know 
what languages they also speak.

Basic search:
$this->Language->find('all');

Result
Language->Artist->ArtistsLanguage<-- Only the record to the language is 
resulting.

Desire
Language->Artist->Language->array(record 1->ArtistsLanguage, record 
2->ArtistsLanguage, etc...)

Comments:
Basically, I am looking to find all artists for a given language. This part 
works, but the result for the list of languages that the artists speaks 
only results in the HABTM model record belonging to the artist.  

How can a do a round trip in a HABTM relationship?

Thanks for all the help,
Jay
Result:

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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