Forums

DB Save (Create) to 3 tables, third one updates wrong table

batvink 21 Feb, 2016
This is a strange one....

One form, creating records in 3 tables (Question, Answer, Question Category)

Question is saved - OK.
(Primary key is questionId, autoincrement)

Answer is saved - OK
(Primary key is answerID, autoincrement)

questionCategory save - tries to update Answer!
(Primary key is questionCategoryId, autoincrement.
questionCategoryId is not on the form.
the selected table is questionCategory.

If I swap Answer and questionCategory save blocks, I get the same problem, but in reverse. It tries to update questionCategory instead of creating Answer.

It also stops before doing a fourth record create to questionCategory. This involves unset()ting the questionCategoryId, changing the category and then creating the second category record.
It failed after I added the Answer block. Prior to this it did 3 successful creates to 2 tables (Question and questionCategory)
batvink 21 Feb, 2016
More info:
I also have unique keys on the tables as well as the primary key, if this affects anything?
The unique key on Answer is QuestionId, AnswerId.
GreyHead 21 Feb, 2016
Hi batvink,

Please drag a Debugger action into the On Submit event, then submit the form and copy and paster the debug results here.

Bob
batvink 21 Feb, 2016
This is the debug info...

Debug Info
Array
(
    [2] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `a_question` (`questionQuestion`, `questionFact`, `questionUserId`, `created`) values ('What is big and like a hill', 'Yep, it's true', '814', '2016-02-21 14:47:32');
                        )

                )

        )

    [9] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `a_answer` (`answerAnswer`, `answerCorrect`, `questionId`) values ('A Mountain', '1', '20');
                        )

                )

        )

    [3] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => UPDATE `a_answer` AS `Data` SET `answerAnswer` = 'A Mountain', `answerCorrect` = '1', `questionId` = '20' WHERE `answerId` = '2';
                        )

                )

        )

    [7] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                        )

                )

        )

)


And the Array data...

Array
(
    [option] => com_chronoforms5
    [chronoform] => New_Question
    [event] => submit
    [categoryId] => 814
    [questionQuestion] => What is big and like a hill
    [answerAnswer] => A Mountain
    [questionFact] => Yep, it's true
    [questionUserId] => 814
    [answerCorrect] => 1
    [submit] => Submit
    [questionId] => 20
    [answerId] => 2
)
batvink 21 Feb, 2016
1 Likes
To coin a technical term, I think it got it's knickers in a twist.
I noticed in the debug that the Update Model was Data. None of the queries have a model ID, although they might have had at some point in the development.

I have set all DB Saves to Save under Model, and then unset them again. Now, it works as designed.

I'll put this down to the database having a bad day.
This topic is locked and no more replies can be posted.