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

Feature request: encoding foreign key arity #362

Open
TeofilC opened this issue Jan 30, 2025 · 2 comments
Open

Feature request: encoding foreign key arity #362

TeofilC opened this issue Jan 30, 2025 · 2 comments

Comments

@TeofilC
Copy link
Contributor

TeofilC commented Jan 30, 2025

When we have a foreign key in Rel8, we don't really know if it's one-to-one or one-to-many.
In fact we don't really distinguish foreign keys from normal values at all.

It would be nice to encode this information somehow. I don't have a concrete design. But it would really help if I could just tell from a glance that a certain line will always succeed or always give exactly one result.

This is always a source of uncertainty when writing or reading queries.

@ocharles
Copy link
Contributor

This has come up at various points I think, but I'm not entirely convinced. I'm mostly worried that the typing overhead is going to become annoying, or impair inference. I could be wrong though - I've never tried! My general advice is to push this in to naming. I encourage FKs be represented by "join functions", like projectOwner :: Project Expr -> Query (User Expr). Maybe this idea could be extented with a naming convention to indicate cardinality: projectOwner1 or something, vs projectCollaboratorsN. Certainly something to think about here.

@TeofilC
Copy link
Contributor Author

TeofilC commented Jan 31, 2025

A naming convention is a good idea!

I was thinking as well, with foreign keys, you know that the query will always succeed, so we could theoretically have projectOwner :: Project Expr -> User Expr. I'm not sure if this makes any sense at all wrt to the implementation, but this would be a nice way to express that there is always exactly one User.

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

2 participants