I have a Workout model and Affiliate model.

Workout belongsTo Affiliate b/c each workout is created by 1
affiliate.
However, I also have a HABTM relationship with Workout and Affiliate b/
c multiple affiliates can view all the workouts, regardless of the
creator, and they can add Workouts as their favorites and add them as
benchmarks.

So, my Workout model is as follows:

<?php
class Workout extends AppModel {
        var $name = 'Workout';
        var $actsAs = array('Containable');

        var $hasMany = array('Wod');
        var $belongsTo = array('Affiliate');
        var $hasAndBelongsToMany = array('Affiliate');
}
?>

The Affiliate model is similar with the same HABTM relationship back
to the Workout. Everything works great until I try to add my new HABTM
relationship...if I output the view array to the debug console I get
the snippet below and my main question is this:

I would expect to get an array under Workout for the
AffiliatesWorkout...however, this array is currently only under the
Affiliate. Is this the correct behavior?

Everything I am doing is based on a specific affiliate so my view is
attempting to show the list of workouts that the affiliate can see.
they can then click the favorite button to add this workout to their
favorite list. I need to make the image yellow or grey based on
whether it's an existing favorite. My current results show all
AffiliatesWorkouts for a given workout...should I expect to be able to
see the AffiliatesWorkout array directly under the Workout or do I
need to cycle through each Affiliate under the workout and check the
favorite flag once I match to the affiliate I'm using?

Array
(
    [Workout] => Array
        (
            [id] => 1
            [affiliate_id] => 1
            [type] => Time
        )

    [Affiliate] => Array
        (
            [id] => 1
            [name] => GLOBAL
            [0] => Array
                (
                    [id] => 4
                    [name] => P3Crossfit
                    [AffiliatesWorkout] => Array
                        (
                            [id] => 4
                            [affiliate_id] => 4
                            [workout_id] => 1
                            [favorite] => 1
                        )

                )

            [1] => Array
                (
                    [id] => 3
                    [name] => Brads Gym
                    [AffiliatesWorkout] => Array
                        (
                            [id] => 5
                            [affiliate_id] => 3
                            [workout_id] => 1
                        )

                )

        )

)


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

Reply via email to