-
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
Allow configuration for relation properties #2256
Comments
It might be possible to add the |
answer: it's not possible to add |
You are correct. The |
@elv1s, thanks for taking this. I just assigned it to you. Thanks! |
Re-posting #2442 (comment):
Here is one reason why we should not mix the property and the relation decorator:
For long term, I would like to propose following API at conceptual level (implementation details will be most likely different): // Relations are defined at model-level
@belongsTo(() => AddressBook)
@model()
class Address extends Entity {
// the foreign key is defined explicitly
@foreignKey(() => AddressBook, 'id')
@property({
length: 36,
postgresql: {
dataType: 'uuid',
},
})
addressBookId: string;
}
// A custom class or interface describes format
// of data returned by a query
@model()
class AddressWithRelations extends Address {
@property()
addressBook?: AddressBook;
}
// Repository API
class DefaultCrudRepository {
find(filter: Filter<Address>): Promise<AddressWithRelations>;
create(data: Address): Promise<Address>;
// ...
} |
Related: in #2152, we will be investigating how to best represent navigational properties in model classes. |
IIUC, using the current implementation, |
The short term fix would be to land the The next, backward-compatible update would be to move relationship decorators to the model and deprecate use on property. |
This issue is essentially a dupe of #2345 and can be closed |
Let's keep this issue, it has been opened first and there is already discussion unfolding here. I am going to close #2345. |
Description
When defining a new relation in a model file, the relation property is also decorated with the
@property
decorator called inside the relation decorator.The problem when creating a relation property this way is that it cannot be configured the same as a standard property.
Current Behavior
For example in the
Order
model, the propertycustomerId
from the@belongsTo
relation cannot be configured to be of typeUUID
(the same type as the definedCustomer
modelid
property):For example, when trying to create a foreign key for "customerId", it fails with an incompatible type error:
Expected Behavior (proposal)
I think that implementing support for property configuration in relation decorators is required.
Ability to config relation properties, kind of:
The text was updated successfully, but these errors were encountered: