Forums

Associative save to multiple data models

erikahepler 05 Oct, 2016
Hi,
I'm banging my head against a wall with this.
I have a CF5 Form (EditUser), which has been called from a CC5 Connection (UserList).
The Connection has multiple data models, including User (pulling from the _users) table and UserInfo (pulling from the Community Builder _comprofiler) table.
The data passes correctly to the form, and it is displayed in the proper fields and can be edited.
On submit, I use a ConnectionAction back to my CC5 Connection to save the data.

However, it only saves the fields that are from the primary data model (User), not from the secondary data model (UserInfo). The debugging info looks good - all the data is in the array correctly.

I have hidden fields on my CF5 form which store the primary keys for both data models.
In the CC5 connection, I have the "Associative save" for the UserInfo model set to "Yes".
What am I missing?

Array
(
    [cont] => lists
    [ccname] => UserList
    [act] => edit
    [gcb] => 623
    [chronoform] => EditUser
    [event] => submit
    [Users] => Array
        (
            [id] => 623
            [name] => Bryna 
            [username] => verena
            [email] => verena@gmail.com
        )

    [UserInfo] => Array
        (
            [id] => 623
            [cb_sca_name] => Verena 
            [cb_member_number] => 12345
            [cb_kingdom] => Middle
            [cb_region_id] => 3
        )

    [button8] => Submit
    [Region] => Array
        (
            [id] => 3
            [name] => Constellation
        )

)
GreyHead 05 Oct, 2016
Hi erikahepler,

I don't think that the CC action can handle a complex save (it's fine for simple single-table ones). So do the DB Saves you need in the form on Submit action, then redirect back to the listing.

Bob
erikahepler 10 Oct, 2016
I'm getting an odd result when I try this. I have added a DBSave action to the Submit action. I select the table (_comprofiler) and the data model (UserInfo), and use the Update Conditions to have it find the record it should be updating. As the logged in user, I am user_id 623. I am editing the record for user 688. I get the following SQL error:

Duplicate entry '623' for key 'user_id' SQL=UPDATE `#__comprofiler` AS `UserInfo` SET `cb_sca_name` = 'Adam1 ', `cb_member_number` = 'unknown', `cb_kingdom_id` = '16', `cb_region_id` = '0', `user_id` = '623' WHERE `UserInfo`.`id` = '688';


Apparently, when it tries to do the DBSave, it adds the user_id field to the Update statement, but uses the user_id of the person who is logged in, rather than the user_id of the person whose data is being updated. No-where do I store the user_id. If I put a Show Stopper immediately before the DBSave, this is what the debugger shows. You can see the array for UserInfo doesn't contain user_id.

Array
(
    [cont] => lists
    [ccname] => UserList
    [act] => edit
    [gcb] => 688
    [chronoform] => EditUser
    [event] => submit
    [Users] => Array
        (
            [id] => 688
            [name] => Adam Smith
            [username] => adam
            [email] => adam@mydomain.com
        )

    [UserInfo] => Array
        (
            [id] => 688
            [cb_sca_name] => Adam Smith
            [cb_member_number] => unknown
            [cb_kingdom_id] => 16
            [cb_region_id] => 0
        )

    [button8] => Submit
    [Region] => Array
        (
            [id] => 0
            [name] => Unknown
        )

    [Kingdom] => Array
        (
            [id] => 16
            [name] => Middle
        )
)


I have tried doing a DBRead of the _comprofiler info on the Load action, saving it to a different data model, in case the UserInfo data model that is passed from the CC somehow had my user_id associated with it. I even listed the fields that I wanted read, without including the user_id field. I get the same result.

Any idea why the user_id field is being included in this Update statement if it isn't anywhere on the form or in the data model?
erikahepler 14 Oct, 2016
Well, I ended up doing a workaround, since I didn't get a response as to why it was forcing the logged-in user's user_id into the UPDATE statement. Instead, I added a Custom Code module to my Submit action, and just wrote my own SQL statement to update the _comprofiler table before doing a ConnectionAction back to the CC Connection with the _users table.
This topic is locked and no more replies can be posted.