-
Notifications
You must be signed in to change notification settings - Fork 3.9k
morph relation : renaming an object #13404
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR implements support for renaming objects that participate in morph relations. In Twenty's system, morph relations enable polymorphic associations where a field can reference multiple object types (e.g., Opportunity -> Company OR Person). When such objects are renamed, the join column names in the database must be updated accordingly.
The implementation adds four key components:
-
New exception handling: Adds
INVALID_ORM_OUTPUT
toObjectMetadataExceptionCode
for handling ORM operation errors during complex metadata operations -
Morph relation field discovery: Introduces
findTargetMorphRelationFieldMetadatas
method to identify morph relation fields that target a specific object being renamed -
Join column name updates: Implements
updateMorphRelationsJoinColumnName
method that updates join column names for MANY_TO_ONE morph relations, with proper type validation and database persistence -
Database migration generation: Adds
updateMorphRelationMigrations
method that creates ALTER migrations to rename join columns while preserving data integrity
The solution integrates into the existing object renaming workflow in object-metadata.service.ts
, following the same pattern used for regular relation updates. When an object like 'Person' is renamed to 'Individual', join columns like 'ownerPersonId' are automatically updated to 'ownerIndividualId' across all morph relations, ensuring referential integrity is maintained.
Confidence score: 3/5
- This change involves complex metadata operations with potential for data corruption if migration logic is incorrect
- The implementation uses sequential database operations in loops which could impact performance and introduce race conditions
- The
findTargetMorphRelationFieldMetadatas
method loads full relations which may cause performance issues in workspaces with many morph relations - Files need more attention:
object-metadata-field-relation.service.ts
(performance concerns with nested loops and sequential saves),object-metadata-migration.service.ts
(migration correctness validation needed)
4 files reviewed, 2 comments
`Settings for morph relation field should be defined ${morphRelationFieldMetadata.fieldMetadata.name}`, | ||
ObjectMetadataExceptionCode.INVALID_ORM_OUTPUT, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Error message includes technical implementation details like 'Settings' and field metadata concepts that users wouldn't understand
const morphRelationFieldMetadataToUpdateWithNewJoinColumnName = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using a more descriptive variable name like updatedMorphRelations
instead of abbreviating to avoid confusion
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:30484 This environment will automatically shut down when the PR is closed or after 5 hours. |
}, | ||
}); | ||
|
||
if (!this.validateFieldMetadataTypeIsMorphRelation(fieldMetadatas)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have created this type validator util in deleted morph field PR, no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was this one for both relation and morph relation but not exaclty the same though
areFieldMetadatasTypeRelationOrMorphRelation
you think i should refactor those util into one ?
...c/engine/metadata-modules/object-metadata/services/object-metadata-field-relation.service.ts
Show resolved
Hide resolved
...c/engine/metadata-modules/object-metadata/services/object-metadata-field-relation.service.ts
Outdated
Show resolved
Hide resolved
📊 API Changes ReportREST Metadata API Analysis ErrorError Output
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
Why
If we have a Morph Relation, like :
Opportunity <-> Company & People
Let's say it's a MANY_TO_ONE on Opportunity side
Then we have two joinColumnNames looking like
Let's say someone renames the obejct Person (assume we can even though standard obejcts cannot be renames per say at the moment in the API)
We need to update the joinColumnName and create the associated migrations