-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow recursively referencing models to be analysed #926
Merged
Conversation
This file contains 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
86116b6
to
6dc595e
Compare
6dc595e
to
cdccca5
Compare
72219f5
to
7b13735
Compare
6cad14f
to
711502f
Compare
7c3e060
to
e9288ca
Compare
8bb9cf4
to
5bbf591
Compare
9d55fb3
to
617e5c9
Compare
f37782d
to
047a8ce
Compare
047a8ce
to
aa66294
Compare
73e6b63
to
d0cb170
Compare
d0cb170
to
326db8c
Compare
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.