Home > other >  Why does changing the variable name in post request doesn't add the string array to db?, expres
Why does changing the variable name in post request doesn't add the string array to db?, expres

Time:10-22

To simplify the question, I have labeled error scenario as Scenario A, working scenario as Scenario B, I would like to know why it does what it does

Scenario A (error)

Step 1 enter image description here

Step 2 & 3 enter image description here

Scenario B (working)

Step 1 enter image description here

Step 2 & 3 enter image description here

I would like to understand why Scenario A does not add the string of array/users to the database? Thanks in advance!

CodePudding user response:

This has to do with the JSON structure. When you simply enter a variable into the JSON without a field name, the variable name defaults to the field name.

For example, given var x = 5, {x} would auto expand to {x: 5} while {y: x} would expand to {y: 5}.

The same logic can be applied to your Cycle object, you're initiating it, in Scenario 1, with {usersA: usersA} instead of {users: usersA}

  • Related