nestjs-boilerplate icon indicating copy to clipboard operation
nestjs-boilerplate copied to clipboard

add custom property

Open seifolah-ghaderi opened this issue 7 months ago • 1 comments

Hi guys, Is it possible to add a property with a complex type in a relational database without a one-to-many relationship?

example: suppose this sudo complex type keeps action information :

 ActionObject: { 
actionResult, 
actionDate,
actionOperator}

and I could use it in my domain :

{
 verificationStatus:ActionObject;
 migrationStatus:ActionObject;

}

I try to find a way that doesn't use multiple separate props for a single status like :

  verifiedDate: Date | null;

  @Column({ type: 'jsonb', nullable: true })
  verifiedResult: object | null;
@Column({ type: 'string', nullable: true })
  verifiedOperator: Date | null;

If is not possible could we add a simple property that mapps to an Enum?

seifolah-ghaderi avatar Apr 13 '25 09:04 seifolah-ghaderi

Try to store the entire ActionObject as a single jsonb column.

@Entity()
export class UserAction {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'jsonb', nullable: true })
  verificationStatus: ActionObject;

  @Column({ type: 'jsonb', nullable: true })
  migrationStatus: ActionObject;
}

Somewhat like this.

Ethics03 avatar May 09 '25 14:05 Ethics03