Skip to content

Fix traversal when parent model is loaded#853

Merged
mvorisek merged 2 commits intodevelopfrom
loaded_id_to_ref
Apr 24, 2021
Merged

Fix traversal when parent model is loaded#853
mvorisek merged 2 commits intodevelopfrom
loaded_id_to_ref

Conversation

@mvorisek
Copy link
Copy Markdown
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
Copy Markdown
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.

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 9 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 requested a review from abbadon1334 April 23, 2021 08:19
@mvorisek mvorisek force-pushed the loaded_id_to_ref branch 2 times, most recently from 602f778 to a121105 Compare April 23, 2021 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants