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

Re-design relational properties #127

Closed
kettanaito opened this issue Oct 12, 2021 · 0 comments · Fixed by #130
Closed

Re-design relational properties #127

kettanaito opened this issue Oct 12, 2021 · 0 comments · Fixed by #130
Labels

Comments

@kettanaito
Copy link
Member

kettanaito commented Oct 12, 2021

Issues

Relational properties are all over the place

First, when creating a relation in the model definition using oneOf/manyOf functions, what you effectively create is a draft for the future relation. Until the relation has access to the entire dictionary (map of models), it cannot know what primaryKey the referenced model has.

This implies that any defined relation must be "evolved".

Unapparent how to re-define relational properties

When updating entities via update/updateMany, you can also update relational properties (support added in #126). However, the implementation for that update is unapparent and seems unsemantic to the Relation class. If forces the updateEntity function to require access to the model definition and the database in order to create a new relational property (the getter it defines on the entity queries the database for the given referenced model's primary key and other data).

Manual retrieval of the referenced model primary key

The relation definition (the one you provide in the model) doesn't know about the referenced model's primary key.

return entityRef[relation.primaryKey]

What's worse, is that in the case of manyOf relations, the referenced entities are stored in a list. So to get an idea of the primary key of the referenced model you have to get the first entity from the referenced list:

// In "manyOf" relation the previous value will be an array of entities.
// Get the first entity and its primary key property name.
const primaryKey = [].concat(prevValue)[0][
InternalEntityProperty.primaryKey
]

Primary key property name cannot be changed on runtime, it's a fixed string. It'd make much more sense to resolve that primary key name when relation definition becomes a relation (is produced). That way there'd be no need to look up primary keys anymore.

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

Successfully merging a pull request may close this issue.

1 participant