Page Contents

Home > @loopback/repository > createHasOneRepositoryFactory

createHasOneRepositoryFactory() function

Enforces a constraint on a repository based on a relationship contract between models. For example, if a Customer model is related to an Address model via a HasOne relation, then, the relational repository returned by the factory function would be constrained by a Customer model instance’s id(s).


export declare function createHasOneRepositoryFactory<Target extends Entity, TargetID, ForeignKeyType>(relationMetadata: HasOneDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>): HasOneRepositoryFactory<Target, ForeignKeyType>;


Parameter Type Description
relationMetadata HasOneDefinition The relation metadata used to describe the relationship and determine how to apply the constraint.
targetRepositoryGetter Getter<EntityCrudRepository<Target, TargetID>> The repository which represents the target model of a relation attached to a datasource.


HasOneRepositoryFactory<Target, ForeignKeyType>

The factory function which accepts a foreign key value to constrain the given target repository