Example of custom field implementation, that stores data as object or array #5318
Replies: 3 comments 4 replies
-
|
Here is example of how the |
Beta Was this translation helpful? Give feedback.
-
|
@MurzNN hi! We have a JSON field for such cases: https://github.com/8iq/nodejs-hackathon-boilerplate-starter-kit/tree/51a7c37/apps/_back02keystone/custom-fields/Json And Some tests for different types of value (Object, Array, String):
This field is working a little differently for mongo and postgres. For example for MongoDB, the value Schema examples:
|
Beta Was this translation helpful? Give feedback.
-
|
@pahaz, thanks for examples! But JSON field is stored in database as one single string, as I understand? We need to store data in semantic way (as Object in MongoDB, and as separate table with relation to entity in SQL), for make filtering queries by individual JSON field values. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Before #195 will be implemented, will be good to have some example of such field, that stores his data in supportable databases (MongoDB or PostgreSQL JSONB field) not as simple JSON text string, but as structured object.
We already have the
MultiCheckfield fromexamples/custom-fieldsthat must do this thing, but in database it store data as simple string, here is example of MongoDB document:{ "_id": "5fd9e6101dab3e967f37364c", "name": "Super Movie", "rating": 4, "categories": "{\"Action\":true,\"Comedy\":true,\"Drama\":false}", "__v": 0 }The first easy problem with current storage type is that I can't filter list of movies by category, for example to select all movies with "Comedy" category. Without this feature - categories field becomes useless.
So will be good to store same data as array, like this:
{ "_id": "5fd9e6101dab3e967f37364c", "name": "Super Movie", "rating": 4, "categories": [ "Action", "Comedy " ], "__v": 0 }or via object like this:
{ "_id": "5fd9e6101dab3e967f37364c", "name": "Super Movie", "rating": 4, "categories": { "Action": true, "Comedy": true, "Drama": false }, "__v": 0 }Also we already have
examples-next/basicexample, that try to implement this viafields-documentfield type, but this is too complex field in implementation.So, can you extend current
MultiCheckfield inexamples-nextto implement array or object storage type (at first - maybe with easy Admin UI showing editable json in textarea), or this is not possible yet?Beta Was this translation helpful? Give feedback.
All reactions