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

Reject create/update requests when data contains navigational properties #3439

Closed
4 tasks
bajtos opened this issue Jul 26, 2019 · 2 comments
Closed
4 tasks
Assignees
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package
Milestone

Comments

@bajtos
Copy link
Member

bajtos commented Jul 26, 2019

Suggestion

When the client attempts to create or update a model and related models in a single call, then we should reject such requests with a helpful error message explaining the problem.

Acceptance criteria

Step 1:

  • Introduce a new protected method DefaultCrudRepository.fromEntity.
  • Update repository methods to call fromEntity whenever we need to convert LB4 Entity into data to be passed to juggler's PersistedModel.
  • This new method is an extension point for app & extension developers, it complements already existing toEntity method and provides functionality similar to LB3 Operation Hook persist.

Step 2:

  • Modify fromEntity to detect navigational properties in data and throw a helpful error.

See #3387 and 5beb7b9 in particular.

IMPORTANT In the spike, fromEntity is accepting options allowing the caller to decide how to treat navigational properties (relations?: true | false | 'throw'). Based on the discussion we had, this is not what we want to implement. Instead, we want fromEntity to ALWAYS REJECT navigational properties.

@bajtos bajtos added feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package 2019Q3 labels Jul 26, 2019
@bajtos bajtos added p1 and removed p1 labels Jul 26, 2019
@jannyHou
Copy link
Contributor

jannyHou commented Aug 1, 2019

estimation meeting discussion:

  • toEntity converts a JSON object(from the database) to an entity class instance
  • maybe we should think of a better name for the function fromEntity, it should do the reverse vs toEntity, then we should put the rejection logic outside the function.
  • some proposal: name it as ensurePersistable, the function makes sure the data doesn't contain non-persistent data.

@agnes512
Copy link
Contributor

agnes512 commented Dec 4, 2019

closing as done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package
Projects
None yet
Development

No branches or pull requests

4 participants