So quick overview of what I'm trying to do. User hasMany BusinessUnitsUser
. BusinessUnit
hasMany BusinessUnitUser
.
In this manner, I've normalized their relationship to two hasManys (I hate working with HABTM related data).
On a new user form, I'd like to give the user the option of adding a new Business Unit at the same time.
Currently, my $this->request->data
array looks like this:
Array
(
[User] => Array
(
[title] => Mr
[first_name] => Kyle
[last_name] => O'Brien
[username] => [email protected]
[producing_office_id] => 4
)
[BusinessUnit] => Array
(
[name] => lskfjsldkfjsdlfk
)
)
Now, this is obviously incorrect, but I'm struggling to think of how to resolve this. I thought giving you a visual of the array, you might be able to tell me what my array should look like.
Here's my relationship array in BusinessUnitsUser
:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'BusinessUnit' => array(
'className' => 'BusinessUnit',
'foreignKey' => 'business_unit_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
EDIT (thanks ndm)
Note the goal: I'm adding a user and I may or may not be adding BusinessUnitsUser
associations as well but I'm definitely also going to be adding a new BusinessUnit
- the form for which exists on the new_user form.
Currently, the User
is saving with a $this->User->saveAll($this->request->data)
but NOT the new BusinessUnit
and certainly not the new BusinessUnitsUser
entry (which I expect to contain the new user id and the new business unit id.