Function StringAttribute

  • A decorator for marking class fields as string attributes within the context of a single-table design entity, with a specific restriction against using foreign key types.

    IMPORTANT! - This decorator explicitly disallows the use of ForeignKey type to maintain clear separation between entity relationships and string attributes for improved data integrity and type safety.

    Type Parameters

    • T extends default

      The entity the decorator is applied to.

    • K extends string

      The type of the attribute, restricted to string attribute values and excluding foreign key types.

    • P extends AttributeOptions

    Parameters

    • Optional props: P

      An optional object of AttributeOptions, including configuration options such as metadata attributes and additional property characteristics.

    Returns ((_value, context) => void)

    A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's string values.

    Usage example:

    class Product extends BaseEntity {
    @StringAttribute({ alias: 'SKU' })
    public stockKeepingUnit: string; // Simple string attribute representing the product's SKU

    @StringAttribute({ alias: 'MyNullableField', nullable: true })
    public myField?: string; // Set to Optional
    }

    Here, @StringAttribute decorates stockKeepingUnit of Product as a simple, non-foreign key attribute, facilitating its management within the ORM system.

Generated using TypeDoc