Using a sub collection as collection in main menu
Is it possible to use buildCollection with a schema that refers to a sub collection?
Basically I have something like this
type Match = {
events: Event[]
}
type Event = {
eventName: string
}
One collection is Matches, which is located at /matches Another is Events which is a sub collection at /matches/{matchId}/events
I'd like both to show up as main menu collections, despite Events being a sub collection.
I understand I have to create a schema for Event, and then pass it to buildCollection. But I'd like to clarify two questions:
- How do I reference another schema using the array datatype? Currently it looks like you have to manually define the object shape in the schema using a map, you can't use another schema as a datatype, unless I've missed something. Sanity also uses a schema and they support the "object" datatype, which essentially refers to another custom schema. So that you can compose different schemas you've previously defined.
Maybe something like this?
export const eventSchema = buildSchema<FirestoreEventT>({
name: "Event",
properties: {
eventName: {
title: "Event Name",
dataType: "string",
}
}
})
export const matchSchema = buildSchema<FirestoreMatchT>({
name: "Match",
properties: {
events: {
title: "Events",
dataType: "array",
of: eventSchema
},
},
});
- How would one define the path for a sub collection in buildCollection? Normally you would just go something like "events", but if we're using a sub collection, I'm not sure what the format would be. Maybe something like "matches/{match_id}/events". I did see your response here but it seems like that referred to a specific document: https://github.com/Camberi/firecms/issues/57
As always, great library, love the new changes in the 1.0.0 beta!
- You can't use the schema as an array
ofprop, but you can isolate the schema properties usingbuildPropertiesand then reuse those:
const eventProperties = buildProperties({
eventName: {
title: "Event Name",
dataType: "string",
}
});
export const eventSchema = buildSchema({
name: "Event",
properties: eventProperties
})
export const matchSchema = buildSchema({
name: "Match",
properties: {
events: {
title: "Events",
dataType: "array",
of: { dataType: "map", properties: eventProperties }
},
},
});
- Regarding this one, I think what you are looking for is a collection group query? https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query We don't support them yet but may consider it for the future!
Perfect, thank you! Are there any particular blockers to getting collection group queries working? I may be able to take a look at them and open a PR.
Hi @fgatti675 any word on support for collection group queries in the future? Or maybe an explanation of the issue so that we can make a PR.
Hi @dhazeley
We don't have immediate plans to support this feature in the near future.
If it gets requested enough we will give it priority over other features.
There are no real blockers for implementing PRs!
If you decide to go for it, I would start from the version 2.0.0 branch master
This is now possible as described here: https://firecms.co/docs/recipes/documents_as_subcollections