Function Attribute

  • A decorator for marking class fields as 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 and NullableForeignKey types to maintain clear separation between entity relationships and scalar attributes for improved data integrity and type safety.

    Type Parameters

    • T extends default

      The entity the decorator is applied to.

    • K extends NativeScalarAttributeValue

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

    Parameters

    • Optional props: AttributeOptions

      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 scalar values.

    Usage example:

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

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

      • (_value, context): void
      • Parameters

        Returns void

Generated using TypeDoc