-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feature: Support nest @Key decorators #96
Comments
I looked into this more. I'm not sure our original idea of simply decorating a nested property with I think the only way to support more complex and arbitrary keys, is going to be through the @Entity({
modelName: 'Order',
key: 'metadata.id'
})
class Order {
name: 'Food Order',
metadata: {
id: 12345
}
} We could also support an array of strings for simple composite keys, as well as a function, allowing very flexible and powerful key generation. For backwards compatibility of course, the current |
Composite key with array notation: @Entity({
modelName: 'Order',
key: ['purchaseOrderNo', 'metadata.id']
})
class Order {
purchaseOrderNo: 'FO_C1',
name: 'Food Order',
metadata: {
id: 12345
}
} Functional option: @Entity({
modelName: 'Order',
key: order => order.metadata.id
})
class Order {
name: 'Food Order',
metadata: {
id: 12345
}
} |
i like both of those options |
After some contemplation, I think I am going to go with only the functional option, to keep things simple and consistent: @Entity({
modelName: 'Order',
key: order => order.metadata.id
})
class Order {
name: 'Food Order',
metadata: {
id: 12345
}
} |
This will be the final feature for NgRx Auto-Entity before its final v12 (to align with Angular v12 back to v9) release. This feature will touch a number of key locations in the code, so I'll release it as a beta initially, but once this feature is done final work can begin on converting the library over to use angular 13 and up (which switches to RxJs v7). |
Looks like this change will have to be fairly extensive, and most likely breaking. For now, I'm going to shelve this issue. Will address at a later date, as being able to specify a custom key retrieval function would be very useful. |
Sometimes the unique identifier is not at the root of an entity. Adding support for nested decoration would be nice.
The text was updated successfully, but these errors were encountered: