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

feat(core): respect naming strategy and explicit field names on embedded properties #4866

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Oct 22, 2023

This is breaking mainly for SQL drivers, where the default naming strategy is underscoring, and will now applied to the embedded properties too. You can restore to the old behaviour by implementing custom naming strategy, overriding the propertyToColumnName method. It now has a second boolean parameter to indicate if the property is defined inside a JSON object context.

import { UnderscoreNamingStrategy } from '@mikro-orm/core';

class CustomNamingStrategy extends UnderscoreNamingStrategy {

   propertyToColumnName(propertyName: string, object?: boolean): string {
      if (object) {
         return propertyName;
      }

      return super.propertyToColumnName(propertyName, object);
   }

}

Closes #4371
Closes #2165
Closes #2361

@codecov
Copy link

codecov bot commented Oct 22, 2023

Codecov Report

Attention: 42 lines in your changes are missing coverage. Please review.

Files Coverage Δ
packages/cli/src/CLIConfigurator.ts 100.00% <ø> (ø)
packages/cli/src/CLIHelper.ts 100.00% <100.00%> (ø)
packages/cli/src/commands/ClearCacheCommand.ts 100.00% <100.00%> (ø)
packages/cli/src/commands/CreateSeederCommand.ts 100.00% <100.00%> (ø)
packages/cli/src/commands/GenerateCacheCommand.ts 100.00% <100.00%> (ø)
...ckages/cli/src/commands/GenerateEntitiesCommand.ts 100.00% <100.00%> (ø)
...ckages/cli/src/commands/MigrationCommandFactory.ts 100.00% <100.00%> (ø)
packages/cli/src/commands/SchemaCommandFactory.ts 100.00% <100.00%> (ø)
packages/core/src/MikroORM.ts 100.00% <100.00%> (ø)
packages/core/src/cache/FileCacheAdapter.ts 100.00% <100.00%> (ø)
... and 161 more

📢 Thoughts on this report? Let us know!.

@B4nan B4nan mentioned this pull request Oct 23, 2023
22 tasks
…ded properties

This is breaking mainly for SQL drivers, where the default naming strategy is underscoring, and will now applied to the embedded properties too. You can restore to the old behaviour by implementing custom naming strategy, overriding the `propertyToColumnName` method. It now has a second boolean parameter to indicate if the property is defined inside a JSON object context.

```ts
import { UnderscoreNamingStrategy } from '@mikro-orm/core';

class CustomNamingStrategy extends UnderscoreNamingStrategy {

   propertyToColumnName(propertyName: string, object?: boolean): string {
      if (object) {
         return propertyName;
      }

      return super.propertyToColumnName(propertyName, object);
   }

}
```

Closes #4371
Closes #2165
Closes #2361
@B4nan B4nan merged commit c64654a into v6 Oct 23, 2023
6 of 8 checks passed
@B4nan B4nan deleted the embedded-field-names branch October 23, 2023 20:33
B4nan added a commit that referenced this pull request Oct 25, 2023
…ded properties (#4866)

This is breaking mainly for SQL drivers, where the default naming
strategy is underscoring, and will now applied to the embedded
properties too. You can restore to the old behaviour by implementing
custom naming strategy, overriding the `propertyToColumnName` method. It
now has a second boolean parameter to indicate if the property is
defined inside a JSON object context.

```ts
import { UnderscoreNamingStrategy } from '@mikro-orm/core';

class CustomNamingStrategy extends UnderscoreNamingStrategy {

   propertyToColumnName(propertyName: string, object?: boolean): string {
      if (object) {
         return propertyName;
      }

      return super.propertyToColumnName(propertyName, object);
   }

}
```

Closes #4371
Closes #2165
Closes #2361
B4nan added a commit that referenced this pull request Nov 2, 2023
…ded properties (#4866)

This is breaking mainly for SQL drivers, where the default naming
strategy is underscoring, and will now applied to the embedded
properties too. You can restore to the old behaviour by implementing
custom naming strategy, overriding the `propertyToColumnName` method. It
now has a second boolean parameter to indicate if the property is
defined inside a JSON object context.

```ts
import { UnderscoreNamingStrategy } from '@mikro-orm/core';

class CustomNamingStrategy extends UnderscoreNamingStrategy {

   propertyToColumnName(propertyName: string, object?: boolean): string {
      if (object) {
         return propertyName;
      }

      return super.propertyToColumnName(propertyName, object);
   }

}
```

Closes #4371
Closes #2165
Closes #2361
B4nan added a commit that referenced this pull request Nov 5, 2023
…ded properties (#4866)

This is breaking mainly for SQL drivers, where the default naming
strategy is underscoring, and will now applied to the embedded
properties too. You can restore to the old behaviour by implementing
custom naming strategy, overriding the `propertyToColumnName` method. It
now has a second boolean parameter to indicate if the property is
defined inside a JSON object context.

```ts
import { UnderscoreNamingStrategy } from '@mikro-orm/core';

class CustomNamingStrategy extends UnderscoreNamingStrategy {

   propertyToColumnName(propertyName: string, object?: boolean): string {
      if (object) {
         return propertyName;
      }

      return super.propertyToColumnName(propertyName, object);
   }

}
```

Closes #4371
Closes #2165
Closes #2361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant