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.
-
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
MultiCheck
field fromexamples/custom-fields
that must do this thing, but in database it store data as simple string, here is example of MongoDB document: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:
or via object like this:
Also we already have
examples-next/basic
example, that try to implement this viafields-document
field type, but this is too complex field in implementation.So, can you extend current
MultiCheck
field inexamples-next
to 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