Skip to content

Fix Migrator with joined/imported fields#1227

Merged
mvorisek merged 8 commits intoatk4:developfrom
PhilippGrashoff:fix_join_fields_created_by_migrator
Aug 5, 2024
Merged

Fix Migrator with joined/imported fields#1227
mvorisek merged 8 commits intoatk4:developfrom
PhilippGrashoff:fix_join_fields_created_by_migrator

Conversation

@PhilippGrashoff
Copy link
Copy Markdown
Contributor

@PhilippGrashoff PhilippGrashoff commented Jul 28, 2024

fix #1226

Currently, migrator does create Model fields that are defined by Model::leftJoin() within the model table when exexuting Migrator::create().
As these fields are defined by a weak join, they should not be created within the model table but their values should be loaded from the joined table on load.

@PhilippGrashoff
Copy link
Copy Markdown
Contributor Author

PR ready to merge

@PhilippGrashoff PhilippGrashoff marked this pull request as ready for review August 5, 2024 19:25
@PhilippGrashoff PhilippGrashoff changed the title Fix that Migrator does create fields defined by a join within the model tabl Fix that Migrator does create fields defined by a join within the model table Aug 5, 2024

if ($field->shortName === $model->idField) {
$refype = self::REF_TYPE_PRIMARY;
$refType = self::REF_TYPE_PRIMARY;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

// functional test for Expression::escapeStringLiteral() method
$strRaw = $model->getPersistence()->typecastSaveField($model->getField('v'), $str);
$strRawSql = \Closure::bind(static fn () => $model->expr('')->escapeStringLiteral($strRaw), null, Expression::class)();
$strRawSql = \Closure::bind(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We would have to do this CS change consistently across all repos which is not easily possible, as \Closure::bind is very often used inside some expr. (like if)

please revert these CS changes - if they were done by your IDE, I advise you to disable them for atk4/* repos at least

foreach ($creatingMigrator->table->getColumns() as $column) {
$expectedFields[$column->getName()] = [
'type' => Type::getTypeRegistry()->lookupName($column->getType()), // TODO simplify once https://github.com/doctrine/dbal/pull/6130 is merged
'type' => Type::getTypeRegistry()->lookupName($column->getType()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this CS change is to be reverted as well - and never place comment below

@mvorisek mvorisek changed the title Fix that Migrator does create fields defined by a join within the model table Fix Migrator with joined/imported fields Aug 5, 2024
@mvorisek mvorisek force-pushed the fix_join_fields_created_by_migrator branch from 1dff9db to ee10160 Compare August 5, 2024 21:44
@mvorisek mvorisek merged commit 7fb3edf into atk4:develop Aug 5, 2024
@mvorisek
Copy link
Copy Markdown
Member

mvorisek commented Aug 5, 2024

Thank you, makes sense!

@PhilippGrashoff
Copy link
Copy Markdown
Contributor Author

Thanks for improving the PR. I only made the CS because the github workflow complained about it.

@PhilippGrashoff PhilippGrashoff deleted the fix_join_fields_created_by_migrator branch August 6, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Migrator::create() adds Fields from Join to Model table

2 participants