Add Relation Metadata (#2388)
* Add Relation Metadata * remove logs * fix migrations * add one-to-many relation inside entities * fix relation * use enum for tenant migration column action type
This commit is contained in:
@ -6,6 +6,7 @@ import {
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
UpdateDateColumn,
|
||||
@ -15,11 +16,13 @@ import {
|
||||
BeforeCreateOne,
|
||||
IDField,
|
||||
QueryOptions,
|
||||
Relation,
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
|
||||
import { FieldMetadataInterface } from 'src/tenant/schema-builder/interfaces/field-metadata.interface';
|
||||
|
||||
import { ObjectMetadata } from 'src/metadata/object-metadata/object-metadata.entity';
|
||||
import { RelationMetadata } from 'src/metadata/relation-metadata/relation-metadata.entity';
|
||||
|
||||
import { BeforeCreateOneField } from './hooks/before-create-one-field.hook';
|
||||
import { FieldMetadataTargetColumnMap } from './interfaces/field-metadata-target-column-map.interface';
|
||||
@ -35,6 +38,7 @@ export enum FieldMetadataType {
|
||||
ENUM = 'ENUM',
|
||||
URL = 'URL',
|
||||
MONEY = 'MONEY',
|
||||
RELATION = 'RELATION',
|
||||
}
|
||||
|
||||
registerEnumType(FieldMetadataType, {
|
||||
@ -61,6 +65,8 @@ registerEnumType(FieldMetadataType, {
|
||||
'objectId',
|
||||
'workspaceId',
|
||||
])
|
||||
@Relation('toRelationMetadata', () => RelationMetadata, { nullable: true })
|
||||
@Relation('fromRelationMetadata', () => RelationMetadata, { nullable: true })
|
||||
export class FieldMetadata implements FieldMetadataInterface {
|
||||
@IDField(() => ID)
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@ -119,6 +125,12 @@ export class FieldMetadata implements FieldMetadataInterface {
|
||||
@JoinColumn({ name: 'object_id' })
|
||||
object: ObjectMetadata;
|
||||
|
||||
@OneToOne(() => RelationMetadata, (relation) => relation.fromFieldMetadata)
|
||||
fromRelationMetadata: RelationMetadata;
|
||||
|
||||
@OneToOne(() => RelationMetadata, (relation) => relation.toFieldMetadata)
|
||||
toRelationMetadata: RelationMetadata;
|
||||
|
||||
@Field()
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
Reference in New Issue
Block a user