CodeIgniter MVC并在一个函数中更新两个不同的表

I have a JavaScript based page where a grid displays all the data for the registered users which is taken from the database.In the UI I have also column named 'groups' which display the groups that every users is participating, but this info is taken using additional two additional tables - 'groups' with 'id' and 'group_name' as columns, and a table 'users_groups' which has 'user_id' and 'group_id' as columns which are foreign keys associated with 'users' and 'groups' tables.

The problem is that when you click to edit any user from the UI grid there an AJAX that post JSON to containing the information for the user which include the 'groups' column which actually is not part of the 'users' table. So I have this:

$data = json_decode($this->input->post('data'), true);

Which originally (when the groups weren't added yet) was transformed in this:

$data = array(
         'id' => $data['id'],
         'email' => $data['email'],
         'firstname' => $data['firstname'],
         'lastname' => $data['lastname'],
         'usertype' => $data['usertype']
          );

And then parsed to the model named 'mUsers' where is the update function:

$query = $this->mUsers->update($data);

And the model since now was very simple because there was only one table:

public function update($data)
    {
        $this->db->where('id', $data['id']);
        $query = $this->db->update('users', $data);

        return true;
    }

But now I have to update another table - 'users_groups' and I'm thinking about my options.Is it possible to just add to the $data array show above another record:

'groups' => $data['groups']

And try to implement all the logic in one function(If this even possible, I couldn't find info if I can have two different active record queries in one function) or the second thing I thought of was after decoding the JSON to make something like:

$dataGroups = array(
    'groups' => $data['groups'] //adding groups data to be fetched for update   
                );

and then parsing the data to a new function, something like:

$q = $this->mUsers->updateGroups($dataGroups);

What would be the better approach in this case?

Thanks Leron

Make both function. And call them when necessary also you will be able to to call only usergroup function alone

//this function update all user data including group
public function updateUser($data, $changeGroup = true)
{
    $this->db->where('id', $data['id']);
    $query = $this->db->update('users', $data);
     if($changeGroup) {
       $this->updateUserGroup($data['id'], $data['groups']);
    }
}

//Update user group
public function updateUserGroup($userid, $usergroups)
{
   //Update user groups
}