Fix HasOneSql imported field update support #1038
Merged
+280
−183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #929
closes #933
fixes atk4/filestore#26
data/src/Reference/HasOneSql.php
Lines 35 to 50 in 6657685
hook code is simply wrong.
In 5d49235 the code was intended to be fixed for changed values for different than
our_field
field. This caused data corruptions like atk4/filestore#26. The data corruption was hotfixed in #1037 but looking into this issue deeper, the hook should simply not be there. We cannot inferour_field
values based on "imported"/"joined" fields, as these fields might not be unique and might represent totaly different relation.The proposed fix maintains the feature for the setting the
our_field
value for a new record with our field equal to null, under this state, we can determine the foreign/their record based on the imported/joined field without the possibility to mismatch the our field. The relation to foreign/their record can still imply duplicates, but this is a decision by the developer.Making the field read only after the record is saved will fix also #929.
The update issue is obvious in https://github.com/atk4/data/blob/3.1.0/tests/ReferenceSqlTest.php#L562 test. How on Earth can "first name" solely uniquely locate a foreign user record?