Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GregBrimble opened this issue Nov 18, 2019 · 1 comment
Labels
question Further information is requested

Comments

@GregBrimble
Copy link
Member

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?

@GregBrimble GregBrimble added the question Further information is requested label Nov 18, 2019
@GregBrimble
Copy link
Member Author

See #45 for the non-singleton Entity implementation.

@GregBrimble GregBrimble pinned this issue Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant