Take this cautiously, it's just an experiment.

I just found an interest for the 'with' parameter when defining an
HABTM when reading the source code.

So I defined that:
        class Estate extends AppModel {
                var $name                               = 'Estate';
                var $hasAndBelongsToMany        = array(
                        'Service'       => array(
                                'with'          => 'EstateService',
                        ),
                );
        }
        class Service extends AppModel {
                var $name                       = 'Service';
                var $hasAndBelongsToMany        = array('Estate');
        }

My view action warned me about a EstateService model, so...
        class EstateService extends AppModel {
                var $name                               = 'EstateService';
                var $useTable           = 'estates_services'; // for some 
Inflector reasons I
didn't care about for now, I must add that or Model search for
estate_services table
        }

And now in my view, I have that:
Array
(
    [Estate] => Array
        (
            [id] => 1
            [name] => lorem ipsum
            [description] => dolor sit amet
            [type_id] => 1
            [created] => 2007-06-20 23:08:03
            [modified] => 2007-06-20 23:10:33
        )
    [Type] => Array
        (
            [id] => 1
            [name] => Apartment
        )
    [Service] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => Service1
                    [EstateService] => Array
                        (
                            [estate_id] => 1
                            [service_id] => 1
                            [comment] => test1
                        )
                )
            [1] => Array
                (
                    [id] => 3
                    [name] => Service2
                    [EstateService] => Array
                        (
                            [estate_id] => 1
                            [service_id] => 3
                            [comment] => test2
                        )
                )
        )
)

Tadaa, did you see the "comment" field? ;)
And thanks to this design, you can also use another table than the
real join-table.

Maybe someone more experimented with this technic can add his comments
please?
Just to confirm I don't misunderstand the purpose of this parameter...

I repeat, take this cautiously, I'm only playing with this thing for
half an hour now

On 20 juin, 22:46, BoSc <[EMAIL PROTECTED]> wrote:
> Does this allow me to update the join-table, also the columns that are
> not really part of the HABTM association?
>
> Also, at the moment I solved this using the Has Many --> Belongs to
> <-- Has many method. The solution was to use the recursive variable.
>
> thanks for the help so far.
>
> On Jun 20, 1:59 pm, Joshua Benner <[EMAIL PROTECTED]> wrote:> 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