Hello,
I’ve completed the mission where we define the relationships between tables, and think I understand the logic behind it, but I am having trouble making it work in a different situation.
In the mission, you use a value from page data to set the relationship. In my case, I want to set the relationship using a fixed value from the other table.
So I have a table called TaxYears which has a column called taxYearEnding:
I also have a table called UserTaxYears, which has a column called yearEnding which has 1-2-1 data object relationship with TaxYears.
The relationship is linked to the column taxYearEnding
When a user creates an account, I want to also create a record in the UserTaxYears table, and create a relationship to the TaxYears table, to set the yearEnding column in UserTaxYears to link to the 2022 value in the taxYearEnding column in the TaxYears table.
I start by creating a new user, and returning the object as a variable newUser in page data. I then set a variable in page data called ownerId with the ownerId from the newUser variable:
I then create a new record in the UserTaxYears table, passing the variable ownerId into the ownerId column of the userTaxYears table. I then return this new record as a property in page data called newRecorduserTaxYears:
Then I create a variable called taxYear which is the 2022 value from the taxYearEnding column of the TaxYears table:
Finally, I attempt to set the object relations and then take the user to the login page:
When I test this, it fails to take the user to the login page, the network tab shows the following:
The record is created in the UserTaxYears table but the data relationship does not exist:
I suspect I may have overcomplicated this! So if there’s an easier way to do it, I’d be very happy to hear it.
I’ve tried a lot of different things to get it to work, but have not been able to do so. Any help much appreciated!