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

fix(Relation): support updating relation without initial value #138

Merged
merged 1 commit into from
Oct 21, 2021

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Oct 21, 2021

GitHub

Root cause

The issue occurred because relation was applied only when parsing the model. So if it wasn't provided an initial value, the entire application was skipped:

if (!get(initialValues, propertyPath)) {
log('relation has no initial value, skipping...')
continue
}

This meant that when you update a parent entity, its relational property (Relation instance) didn't have source set at all, throwing an exception. This is not correct, even relational properties without initial values must be applied.

Changes

  • Relation is no longer resolved when applied.
  • All relations are applied when defining relational properties, but only those with initial values are resolved. This sets the necessary target/source properties on the Relation instance but does not define a proxy getter property.
  • Rewrites relation test to assert exact data structures (makes tests more precise).

'Failed to define a "%s" relational property to "%s" on "%s": cannot find a model by the name "%s".',
relation.kind,
propertyPath,
entity[ENTITY_TYPE],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relation.source.modelName is not yet set.

@kettanaito kettanaito merged commit 882eb28 into master Oct 21, 2021
@kettanaito kettanaito deleted the 137-update-relation-without-initial-value branch October 21, 2021 14:26
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

Successfully merging this pull request may close these issues.

Cannot update relation if not initially defined
1 participant