Module CustomFields Dev: Difference between revisions

Jump to navigation Jump to search
Line 98: Line 98:
(table_name, column_name) both forms the primary key of the table, and links to columns (custom fields) of other customfields tables.
(table_name, column_name) both forms the primary key of the table, and links to columns (custom fields) of other customfields tables.
extraoptions is a blob, which allows to store the data as binary (as-is) without encoding (which solves a big problem of JSON which is encoding special and foreign characters, here there is no problem at all).
extraoptions is a blob, which allows to store the data as binary (as-is) without encoding (which solves a big problem of JSON which is encoding special and foreign characters, here there is no problem at all).
When fetching custom fields, the module simply JOIN the extraoptions table, which adds an '''extraoptions''' column for each custom field in the SQL result. Then it is quite easy to just json_decode() the data returned inside the extraoptions column.
This methodology allows to have all the advantages of a relational database, with the flexibility of a free-schema model:
* everything is stored inside the database (only one storage place)
* fixed columns allows for relational joining and optimization
* thus queries (fetching) are optimised
* at the same time, the extraoptions are automatically retrieved and associated with every custom field, and whenever needed they can be used
* and thus we also get a flexible model to '''add extra (virtual) columns whenever needed''' without having to alter the relational database schema
Thus no critical information is and should be stored inside the extraoptions column because they would not be query-able, only extra options that are just used to tweak the management of those fields inside the PHP application should be stored. But this is a wonderful way to add non critical informations that still allows to develop more complex features and management for special custom fields.


== CustomFields JSON API ==
== CustomFields JSON API ==
439

edits

Navigation menu