Have a look in Model::__saveMulti(). I still haven't quite figured out
the logic but the HABTM model's save() is called (which would trigger
its callbacks) in some instances. But it's still a bit foggy to
myself, as well. For instance, the block beginning at line 1286
starting with:
foreach ((array)$data as $row) {
... doesn't make any sense to me at all. I can't understand how that
could work properly.
On Tue, Jan 20, 2009 at 5:02 AM, Martin Westin
<[email protected]> wrote:
>
> bump...
>
> My current working theory is that for some (to me) unknown reason
> (performance?) habtm relationships are created and deleted without
> fully utilizing the joining model. That is when you do:
>
> $data = array(
> 'A' => stuff for A,
> 'B' =>array('B'=>array(1,3,4))
> );
> $this->A->save($data);
>
> So I am thinking that I have to change the way I save these.
> Possibly I need to g as far as using $this->AB->delete() directly for
> unlinking.
>
> And, or-course, anyone who has been down this road before could be of
> great help by nudging me in the right direction.
>
> Non-essential background information:
> The reason I want to use the save and delete callbacks is that I want
> to put together a custom "counterCache" for a habtm relationship. That
> is why I want to trigger an update each time a "link" is created or
> deleted.
>
> /Martin
>
> On Jan 19, 8:56 am, Martin Westin <[email protected]> wrote:
>> Hi there,
>>
>> I am trying to make use of a JoinModel for the first time but can't
>> get the hang of it. First I had some problems getting the class to
>> load at all but that is taken care of. Now I cant get all the
>> callbacks to fire.
>>
>> I create associations between records of my two models expecting
>> beforeSave and afterSave to fire. But they don't.
>>
>> I know the joining model is being used ($this->ModelA->ModelAsModelB
>> == instance of my expected class) and callbacks beforeFind and
>> afterFind are firing.
>>
>> I found two old posts. One suggested using beforeSave (for whatever
>> purpose), suggesting to me that they should fire. The other suggested
>> using a callback on one of the "primary" models to call a custom
>> method on the joining model, suggesting that the callbacks should in
>> fact not fire.
>>
>> Looking at the models used in the core tests I found no joining model
>> with any callback defined.
>>
>> Does this mean that a joining model is really only "half a model"?
>> Since I haven't found anything to clearly state the opposite I have
>> expected these models to behave like any other once created. can
>> anyone clear the fog a little for me?
>>
>> /Martin
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---