Skip to content
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
merged 16 commits into from
Mar 16, 2024

Conversation

mvorisek
Copy link
Member

@mvorisek mvorisek commented Nov 23, 2021

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 your Model::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.

@mvorisek mvorisek force-pushed the guard_addfield_recursion branch 3 times, most recently from 86116b6 to 6dc595e Compare November 24, 2021 11:48
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch from 6dc595e to cdccca5 Compare December 3, 2021 23:55
@mvorisek mvorisek marked this pull request as draft June 3, 2022 16:18
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch 3 times, most recently from 72219f5 to 7b13735 Compare February 27, 2024 12:34
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch 6 times, most recently from 6cad14f to 711502f Compare March 7, 2024 12:04
@mvorisek mvorisek changed the title Guard Reference::addField/addTitle recursion Add Reference::createAnalysingTheirModel() method Mar 7, 2024
@mvorisek mvorisek added the MAJOR label Mar 7, 2024
@mvorisek mvorisek changed the title Add Reference::createAnalysingTheirModel() method Impl. Reference::createAnalysingTheirModel() method Mar 7, 2024
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch 13 times, most recently from 7c3e060 to e9288ca Compare March 9, 2024 22:58
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch from 8bb9cf4 to 5bbf591 Compare March 15, 2024 21:27
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch from 9d55fb3 to 617e5c9 Compare March 16, 2024 00:31
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch from f37782d to 047a8ce Compare March 16, 2024 15:48
@mvorisek mvorisek marked this pull request as ready for review March 16, 2024 15:50
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch 2 times, most recently from 73e6b63 to d0cb170 Compare March 16, 2024 17:42
@mvorisek mvorisek force-pushed the guard_addfield_recursion branch from d0cb170 to 326db8c Compare March 16, 2024 17:46
@mvorisek mvorisek merged commit 60869be into develop Mar 16, 2024
31 checks passed
@mvorisek mvorisek deleted the guard_addfield_recursion branch March 16, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant