A function returning the constructor of the target entity class T
. This function is essential for dynamically establishing the relationship, helping to circumvent circular dependency issues.
Configuration options for the one-to-one relationship, particularly the foreign key within the target entity that links it back to the source entity. This setup is critical for accurately linking and managing the entities involved.
A class field decorator function that, when applied to a field, registers the one-to-one relationship in the ORM's metadata system. The registration includes the target entity and the specified foreign key, ensuring that the ORM correctly interprets and maintains the relationship.
Usage example:
class User extends TableClass {
@HasOne(() => Profile, { foreignKey: 'userId' })
public profile?: Profile;
}
class Profile extends TableClass {
@ForeignKeyProperty()
public readonly userId: ForeignKey;
@BelongsTo(() => User, { foreignKey: "userId" })
public readonly user: User;
}
Here, the @HasOne
decorator is applied to the profile
field of the User
class, establishing a one-to-one relationship between a User
and a Profile
. The foreign key (userId
) in the Profile
entity points back to the User
entity, enabling the ORM to manage this relationship by linking a user to at most one profile.
Generated using TypeDoc
A decorator for defining a one-to-one relationship between entities in a single-table design ORM system. This relationship implies that an instance of the entity to which this decorator is applied can be associated with at most one instance of another entity. The
HasOne
decorator plays a crucial role in establishing and managing such relationships by automatically registering the necessary metadata, thereby enabling the ORM to recognize and navigate these associations effectively.