I never do that directly.
What I do is that I update either of the models involved with the
association either added or removed.

This si an example straight out of a project I am working on. It is
for Cake1.2. A quick disclaimer though:  It may not at all be the best
way and it may not at all be obvious what it does since it is all
ongoing pre-release stressed-out code. It also helps to have read up
on how HABTMs are saved.

I have two models involved. User and Module. They are HABTM
associated, creating kind of like a simple high-level permission. The
following code is found in the User model and is used to toggle the
association on and off between a user and a module. ($user is passed
as a User-array since the controller or other part of the model may
want to update other fields before calling this method)

---start---

function toggleModule($user, $module_id)
{
    $new_mod = $this->Module->findById($module_id);
    if ( $new_mod )
    {
        $existing_ids = Set::extract($user['Module'], '{n}.id');
        if ( in_array($new_mod['Module']['id'], $existing_ids) )
        {
            foreach ( $existing_ids as $i => $id )
            {
                if ( $id == $new_mod['Module']['id'] )
                {
                    unset($existing_ids[$i]);
                }
            }
        }else{
            $existing_ids[] = $new_mod['Module']['id'];
        }
        unset($user['Module']);
        sort($existing_ids);
        $user['Module']['Module'] = $existing_ids;
        $this->save($user);
        return true;
    }else{
        return false;
    }
}

---end---

Just ask if something if unclear and I'll try to answer as best I can
/Martin


On Apr 17, 8:39 am, . <[EMAIL PROTECTED]> wrote:
> How do you do a delete or update a row in a HABTM table in cake 1.2?
--~--~---------~--~----~------------~-------~--~----~
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