Are non-array nested object fields in the data model, allowed to be flattened as models?
In that case, sorry for the false bug report. I did not get it from your documentation, that this is a no-go. Anyway, that is what I did and might the reason why we are seeing this behaviour. Moreover, it causes another bug on creation of a new address. If this is indeed not supported behaviour, maybe might be cool to implement a fail-safe informing the developer through an error, that this sort of configuration is not possible, i.e. only array fields may be configured asModels.
For information, I’m working on a fix on your first problem regarding the computed field “full address” not being correctly retrieved when used as a reference field.
Using asModels on a non-array field should be supported because it’s not a lot different from using it on array fields. Right now it seems to have some limitations, but we’ll fix them.
I’ll work on a second fix regarding the creation when the first one will be released.
Please note though that address creation will only be possible on an existing client: as addresses are attached to client objects, it won’t be possible to create an address first, and then a client.
That’s good to hear. It would be helpful to use asModels on a non-array field. I will apply this to visually improve the structure of the Details view of field-heavy collections.
I’ll wait for your fixes then.
That makes sense. Is there a way to programmatically avoid this option to appear in the UI? Our operators will find it and then report this as a bug.
We released @forestadmin/datasource-mongoose@1.5.15 fixing the issue with computed fields. You can upgrade to this version and use computed fields as expected.
Regarding the possibility to hide the address creation, I would suggest to not give the right to create addresses to users. You can remove this possibility in the roles tab in your project settings (once deployed in production or on a remote environment).
It might be useful though to create addresses along with clients, which is possible with the option … asFields but at the moment you cannot use both asFields and asModels at the same time on the same field.
I think it might be possible using the flattener plugin (see the docs here) in addition to asModel. But right now we have the same creation bug than the one we need to fix.
Sorry for the late reply, I was focused on some other threads.
So, I’m running @forestadmin/datasource-mongoose:1.5.19.
There is a non-array nested object field of my MongoDB data model, called x. I added x to the asModels array of the built-in field flattener for that model.
Unfortunately, when I navigate to the computed record, which corresponds to that field x (detail view), the server freezes, i.e. the HTTP request stalls.
It’s not much information, but maybe you can suggest me a line number in the distribution, where to put a breakpoint (js, not ts) and share some variable data?
So, the faulty behaviour is happening, if I upgrade @forestadmin/datasource-mongoose from 1.5.15 to 1.5.16. I once saw a MongoPoolClearedError, but I am not certain if this is the culprit.
In this situation, I can not upgrade past 1.5.15 to test the new functionality, so we would need to fix this, before I can mark this issue as solved.
Is it possible to share a repository that reproduces this bug, as you did with the previous one? On my side when I navigated to records everything worked smoothly so I would need more info to reproduce the issue.
Thanks. Mongodb is running locally on 27017, but I get the following error when setting up the project:
× Cannot connect to the database due to the following error:
× {"name":"MongoServerSelectionError","reason":{"type":"Single","setName":null,"maxSetVersion":null,"maxElectionId":null,"servers":{},"stale":false,"compatible":true,"compatibilityError":null,"logicalSessionTimeoutMinutes":null,"heartbeatFrequencyMS":10000,"localThresholdMS":15,"commonWireVersion":null}}