Open michi88 opened 1 year ago
Hi @michi88
Before jumping into your code to investigate, if I understand correctly, you are looking for a solution for storing a reference path like a string, but still be able to use the reference functionality of the CMS.
If that is the case, the simplest way I can think of making it work is using EntityCallbacks
: onFetch
and onPreSave
for adapting your data model.
Also, keep in mind that you don't need to fetch the entity for building the reference as you do inside AsyncPreviewComponent
, the path and id retrieved will be the same ones you input.
Hope this helps
Thanks for leaving a comment here @fgatti675
What do you mean by that I do not need to fetch the entity? I'm inputting entityId: obj[referenceId]
which would be the id stored in the main document together with the path from the config, right?
Also, when I'm using EntityCallbacks: onFetch
and set the fetched values on the object as a map, they are only rendered in the list when I open the details dialog. Any way to get around that? I guess AsyncPreviewComponent
should be used somehow? As I want to show multiple fields of a doc that needs to be fetched, I'd like to avoid loading the related doc for every field.
This may be a bit confusing but bear with me here.
While trying out this project I was stumped for a long time why a reference field was not working. I would always get
Data is not a reference
.What I actually didn't know, and is not specified in the docs anywhere, is that this requires a Firebase reference field type. I'm guessing this field type is not being used a lot as it is not pushed in any Google docs as well. At least I'm not using it. The default in projects I see is to just use an ID of the referenced objects and build the paths in code to fetch data etc.
I understand that we need to provide some more data for FireCMS to be able to correctly fetch the referenced object(s) etc. but from a user perspective one would only need to provide a function to build the path maybe? Or if the path is just a collection and an entity ID, we'd only need that info.
Did a quick POC how it can work for reading/displaying these types of fields:
You could make an helper like this:
Suppose you have an
Organization{name: string}
collection and anAccount{name: string, organizationId: string}
collection. You can then use it in additional fields like so:This way at least we can render these fields but updating of course does not work.
Questions:
dataType: 'reference'
requires a firebase reference?For number 2. Say we have this fictional referenceById datatype:
Then we'd know the base path ("organizations"), the field that holds the ID ("organizationId") and the value we have while rendering the entity. I understand this does not always work when dealing with subcollections and stuff so maybe a pathBuilder func needs to be provided by the user that takes the entity being rendered / updated or something but initially this was why I was confused as I thought this should work.
Hoping this issue will also save some googlers (and future ChatGPT ;-)) time figuring out what is going on.
Last but not least, thanks for the efforts here, I think FireCMS is something the Firebase ecosystem is lacking. We haven't decided yet if we'll adopt this in our projects but if we will, we will be sponsoring. Keep up the good work!