Allow recursively referencing models to be analysed#926
Merged
Conversation
86116b6 to
6dc595e
Compare
6dc595e to
cdccca5
Compare
72219f5 to
7b13735
Compare
6cad14f to
711502f
Compare
7c3e060 to
e9288ca
Compare
d0e5821 to
de33f94
Compare
88d0ce4 to
8bb9cf4
Compare
8bb9cf4 to
5bbf591
Compare
9d55fb3 to
617e5c9
Compare
f37782d to
047a8ce
Compare
047a8ce to
aa66294
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Use dark magic to overcome natural recursion of recursively referenced models.
fix hardcoded HasOne type - https://github.com/atk4/data/blob/5.0.0/src/Reference/HasOne.php#L30
other examples are https://github.com/atk4/data/blob/5.0.0/tests/RandomTest.php#L70
BC break - model init / persistence might be required earlier
HasOne cannot be traversed (via
->createTheirModel()or->ref()) without persistence set. Newly, our field type is infered, and as their model needs to be created for that, persistence must be set early to make the their model initialized.Also make sure
parent::init()is called always as the first statement in all yourModel::init()methods.BC break - possible infine recursion
As we now infer their field type in HasOne, recursive models must use the strictly the same seed.
If your code ends with infine recursion, you need to take an action. If not, there is no BC break.
If you define their model as
['model' => new TheirModel()], replace it with['model' => [TheirModel::class]].BC break - persistence can be referenced forever (only for PHP 8.2 and lower)
WeakMap values do not participate in GC. If you do not reopen connections to DBs during (one request/script run), no action is needed.