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

Fix traversal when parent model is loaded #853

Merged
merged 2 commits into from
Apr 24, 2021
Merged

Conversation

mvorisek
Copy link
Member

@mvorisek mvorisek commented Apr 15, 2021

finish after #855, #860, #861

discussion here: c8cbce3#r49718142

fixes https://github.com/mvorisek/atk4-hintable-mirror/blob/1.2.1/tests/Data/HintableModelTest.php#L120

$model = new Model\Standard($db);
$model->load(2)->simpleMany->loadAny()->id;

must traverse from model with ID = 2 only (before this PR, ID = 2 condition was not applied and it was required to be added manually, now with entity concept we can assume locked ID)

note: this works also with $model->load{One, Any}()->simpleMany and also with Model::duplicate() which will unset the ID correctly.

Copy link
Member

@DarkSide666 DarkSide666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I don't think this is correct approach.
Loading record shouldn't add condition to model because that will limit how getTitles(), export() and other dataset-wise methods will work when model is or is not loaded. That shouldn't happen.

tests/RandomTest.php Outdated Show resolved Hide resolved
src/Persistence/Sql.php Show resolved Hide resolved
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 2 times, most recently from f519577 to 14a1a34 Compare April 19, 2021 21:10
@mvorisek mvorisek marked this pull request as ready for review April 19, 2021 21:11
@mvorisek
Copy link
Member Author

All changes reverted and addressed differently, getTitles() and other confusing behaviour with entity (loaded model) now thow because of #855

// add entity ID to scope to allow easy traversal
if ($model->id_field && $model->getId() !== null) {
$query->group($model->getField($model->id_field));
$query->having($model->getField($model->id_field), $model->getId());
Copy link
Member Author

@mvorisek mvorisek Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: having with group by is like where, but it does not apply after aggregate functions.

@DarkSide666 DarkSide666 self-requested a review April 19, 2021 21:18
Copy link
Member

@DarkSide666 DarkSide666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in advance. Need to fix this approach for MS SQL

@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 10 times, most recently from d23156b to 83077c2 Compare April 20, 2021 07:20
@mvorisek mvorisek marked this pull request as draft April 20, 2021 08:09
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 4 times, most recently from 8c2ab17 to 02df81d Compare April 20, 2021 09:18
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 3 times, most recently from 5588b33 to 6834cd4 Compare April 21, 2021 11:42
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 2 times, most recently from cee8d38 to bf48e54 Compare April 22, 2021 12:44
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 10 times, most recently from 3781e5f to 85c1345 Compare April 22, 2021 14:49
@mvorisek mvorisek marked this pull request as ready for review April 22, 2021 14:52
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 3 times, most recently from a121105 to 1836826 Compare April 23, 2021 12:12
@mvorisek mvorisek merged commit 184421a into develop Apr 24, 2021
@mvorisek mvorisek deleted the loaded_id_to_ref branch April 24, 2021 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants