Skip to content

[RFC] Throw an EntityNotFoundError when loading a non-existent singleton Entity? #46

@GregBrimble

Description

@GregBrimble

If you attempt to load a non-singleton Entity which does not exist, an EntityNotFoundError is thrown:

@Entity({ datastore })
class ComplexEntity {

    @Column({ isPrimary: true })
    public id: string

    constructor(id: string) {
        this.id = id
    }
}

const complexRepository = getRepository(ComplexEntity)

const complexInstance = new ComplexEntity('12345')
await complexRepository.save(complexInstance)

await complexRepository.load('12345')  // returns a new ComplexEntity instance

await complexRepository.load('99999')  // throws EntityNotFoundError

This behaviour is not found with singleton Entities:

@Entity({ datastore })
class SingletonEntity {
    // ...
}

const singletonRepository = getRepository(SingletonEntity)

const singletonInstance = new SingletonEntity()

await singletonRepository.load()  // returns a new SingletonEntity instance <--

await singletonRepository.save(singletonInstance)
await singletonRepository.load()  // returns a new SingletonEntity instance

Should the indicated line (<--) throw an EntityNotFoundError? If so, why? If not, why not?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions