I did something similar, where 'faculty' has and belongs to many
'activity' and each link has a student count associated with it -- I
used a custom finderQuery in the definition of the association to pull
the student count field with all the other data (TSQL, so some minor
differences from MySQL, and this works with cake 1.2):

var $hasAndBelongsToMany = array(
            'Activity' => array('className'  => 'Activity',
                                'joinTable'  => '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
        [activities] AS [Activity]
        JOIN [activity_links] AS [ActivityLink] ON [ActivityLink].
[activity_id] = [Activity].[id]
WHERE
        [ActivityLink].[faculty_id] = {$__cakeID__$}
ORDER BY
        [Activity].[name] ASC'
                          )

On Jun 20, 6:03 am, BoSc <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have three tables:
>
> cities
> categories
> categories_cities
>
> The first two are normal tables, the third one is used for linking.
> Since I want to be able to indicate if the link is active, I've added
> a column active to the categories_cities table. Using HABTM I am not
> able to access any data of the categories-cities table caus it's used
> for linking only. Is there any way to do make this work?
>
> I've considered using the Has Many, Belongs to method, but in someway,
> using the findAll method doesn't return data in a deep enough
> recursive way.
>
> Any thoughts?


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