-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
It would be an interesting addition to be able to provide a selector for the parent collection. For example:
// Only add a chairCount on furniture of type "table"
Furniture.cacheCount({
collection: Furniture,
referenceField: 'furnitureLink',
cacheField: 'chairCount',
parentSelector: { type: 'table' },
selector: { type: 'chair' },
})
// Only add a legCount on furniture of type "chair"
Furniture.cacheCount({
collection: Legs,
referenceField: 'furnitureLink',
cacheField: 'legCount',
parentSelector: { type: 'chair' },
})This allows "polymorphic" collections to have different caches depending on their category, type, etc.
It is mostly done for keeping things clean, but one could also imagine using different cache configurations with the same name:
Here's a sarcastic example π€£:
Users.cacheCount({
collection: Users,
referenceField: 'friendIds',
cacheField: 'americanFriends',
parentSelector: { citizenShip: 'american' },
selector: { citizenShip: 'american' },
})
Users.cacheCount({
collection: Users,
referenceField: 'friendIds',
cacheField: 'americanFriends',
parentSelector: { citizenShip: 'european' },
selector: { citizenShip: { $in: ['north-american', 'south-american', 'american'] } },
})You would be responsible for maintaining non-overlapping parent selectors of course, otherwise it will not work.
mfen, Fen747 and armellarcier
Metadata
Metadata
Assignees
Labels
No labels