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

Enforcing minimum relationships #39

Open
ErisDS opened this issue Aug 28, 2019 · 0 comments
Open

Enforcing minimum relationships #39

ErisDS opened this issue Aug 28, 2019 · 0 comments

Comments

@ErisDS
Copy link
Member

ErisDS commented Aug 28, 2019

Normally:

  • hasOne = has 0 or 1 child
  • hasMany = has 0, 1, or many children
  • belongsToMany = belongs to 0, 1 or many parents

However in some cases you might want more explicit relationships like:

  • hasExactlyOne = always has 1 child
  • hasAtLeastOne = has 1 or many children
  • belongsToAtLeastOne = belongs to 1 or many parents

I can imagine in some cases there are even more complex enforcements, like having exactly X relations.

Bookshelf doesn't provide any of this behaviour, but bookshelf relations has the ability, I think, to enforce this kind of rule and abstract away the logic.

In Ghost we already have a use case for hasAtLeastOne with authors and potentially a case for hasExactlyOne for dividing the post table up behind the scenes to improve performance.

We maybe should add a way to configure these extra constraints in bookshelf-relations somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant