I had a similar setup in an application -- my solution was to write a 
custom finderQuery. There are several posts on the message board about 
doing this, but I'll paste my code below. Bear in mind the query below 
is TSQL, so it might be a little unfamiliar if you're used to MySQL. 
Also, this code is written for CakePHP 1.2.x -- I'm not sure if there 
are differences required here for 1.1.x.

Three tables:

faculty (id, name, etc)
activities (id, name, etc)
activity_links (id, faculty_id, activity_id, students)

I wanted to pull the link ID and student count along with each activity 
that was linked to the faculty. Below is how I did it in the faculty model.

var $hasAndBelongsToMany = array(
        'Activity' => array('className'  => 'Activity',
                            'joinTable'  => 
'facultyWorkload_activity_links',
                            'foreignKey' => 'faculty_id',
                            'associationForeignKey' => 'activity_id',
                            'unique'     => true,
                            'finderQuery' => '
SELECT
    [Activity].[id] as [Activity.id],
    [Activity].[name] as [Activity.name],
    [Activity].[activity_type_id] as [Activity.activity_type_id],
    [Activity].[credits] as [Activity.credits],
    [ActivityLink].[students] as [Activity.students],
    [ActivityLink].[id] as [Activity.activity_link_id]
FROM
    [facultyWorkload_activities] AS [Activity]
    JOIN [facultyWorkload_activity_links] AS [ActivityLink] ON 
[ActivityLink].[activity_id] = [Activity].[id]
WHERE
    [ActivityLink].[faculty_id] = {$__cakeID__$}
ORDER BY
    [Activity].[name] ASC'
                      ));

3mind wrote:
> Is possible have a join attribute in a findall result?
>
> I have 3 table:
>
> user(id,name)            [var $hasAndBelongsToMany = array('Phone' =>
> array('className'  => 'Phone']))]
> user_phone(user_id,phone_id,myattribute)
> phone(id,number)      [var $hasAndBelongsToMany = array('User' =>
> array('className' => 'User'))]
>
> How i obtain "myattribute" when i do $this->User->findall() in the
> User controller?
>
> Is possible?
>
>
> >
>   

--~--~---------~--~----~------------~-------~--~----~
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