my issue is with the last foreach to process the $modelsLegsRates. It returns an error:
PDOException: SQLSTATE[23000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Violation of UNIQUE KEY constraint ‘FK_projects_legs_rates_LegId’.
but there should be no duplication. The previous loop save each $modelLeg, so they will have a unique PK value, and then I loop over each and assign it to the $modelsLegsRate->LegId.
I have confirm that the project ($model) is created, each leg ($modelLegs/$modelLeg) is properly created, and the 1st ($modelsLegsRates/$modelsLegsRate) is created, but every subsequent one generates this error.
In the most inner foreach loop you are assign the same LegId to the bunch of modelsLegRate objects. And it looks like you have unique key constrain in the table mapped to the object modelsLegsRate (in your mssql db, it even has it’s name). Can you show us schema of the table (keys and constrains)?
I can if you truly think it will be helpful, but in this instance the schema is not the issue and the constraint is fine. I believe this to simply be a PHP coding issue.
Let me elaborate. I’m using the dynamicform to allow multiple entries within the main project. So a Project can have multiple Leg and each Leg will then have a single Leg Rate
My issue is simply assigning the LegId to the corresponding Leg Rate
I truly think it will be helpful
The error message points quite clearly “FK_projects_legs_rates_LegId”. I bet it is Foreign Key constrain on ‘ProjectsLegsRates’ table. Can we see it?
I finally resolved the issue. It was a coding, not understanding the way that Yii bring s back the data from the page. Since this is a 1-1 relationship, I was able to eliminate the loop and simply process the first element in the array and everything worked perfectly.