-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
relation expects foreignKey on the Object #1719
Comments
I think it's possible for TypeScript to exclude some properties explicitly using type OrderWithoutUserId = Pick<Order, Exclude<keyof Order, 'userId'>> |
@raymondfeng That worked in terms of TS Validation BUT it breaks the explorer whereby |
Yes, I commented in #1722. We need to have a way to reflect such TS types in OpenAPI spec. |
The problem may be easy to fix - see the discussion in #2658 and the following code: |
Description / Steps to reproduce / Feature proposal
When I was working on user order history component for https://github.com/strongloop/loopback4-example-shopping I ran into an issue ...
/users/{userId}/orders
expects the orders object to have auserId
field (Since it's a required property of theOrder
model and is enforced by the controller coercion / validation). The issue is that passing in theuserId
on the Order object passes controller validation but causes the relation validation to throw an error saying the foreign key can't be changed -- despite the fact that the foreign key is exactly the same as the one in the URL and the one given to the repository.Current Behavior
Throws error if foreign key on object saying you can't change it even if it's the same one.
Expected Behavior
Be smart enough to not throw an error if the key given is the same as the one that's expected.
My current solution is to delete the foreign key in the controller. The other alternatives I can think of is to mark the key as an optional property (do we want this?) ... or to mark the
requestBody
type asPartial<Order>
but this will mean losing type validation of expected properties on the Order type.See Reporting Issues for more tips on writing good issues
The text was updated successfully, but these errors were encountered: