strapi-connector-firestore
strapi-connector-firestore copied to clipboard
Feature: Populate designated fields when storing references
Relations are stored as references in Firestore database. In some situations (when accessing the database natively, not via the Strapi API) it may be convenient to have certain values from the target document stored alongside the entry.
In such a way, key data from the relation would be immediately available without need to fetch the target document.
Proposed configuration API, add a populate field to relation attributes:
{
attributes: {
owner: {
model: "owner",
autoPopulate: true, // Not to be confused with existing config for REST API
populate: ["name"] // "name" refers to an attribute on the "owners" model
}
}
}
When an entity of such a model is stored, it may look like:
{
owner: {
ref: '/owners/abcd1234', // Original DocumentReference
name: "John Doe" // Current value of the the "name" field on the target document
}
}
Cannot populate attributes with reserved names: "ref", "id" (conflicts with DeepReference) or "filter" (conflicts with MorphReference).
Such functionality only impacts how the data is stored, and it has no impact on API responses.
How to handle or support "deep" populating?
Consider if the owner model has a photo relation, and we want the photo's url populated on the original object, and customise the name of the field. E.g.
{
attributes: {
owner: {
model: "owner",
populate: {
name: 'name',
photoUrl: 'photo.url'
}
}
}
}
When an entity of such a model is stored, it may look like:
{
owner: {
ref: '/owners/abcd1234', // Original DocumentReference
name: "John Doe", // Current value of the the "name" field on the target document
photoUrl: "https://..." // Current value of the "url" field on the target of the current value of the "photo" field of on the target document
}
}