Answer the question
In order to leave comments, you need to log in
How to store context dependent values?
Hey! Here and there I come across a problem when it is necessary to save (in a relational database) the state of an entity that depends on some context.
I put the "Drupal" tag, because in Drupal there is definitely something like that)) Drupal people, tell me!
I will give an example for clarity.
There is a form field for entering news text. We want to set up a tooltip description and a set of wysiwyg editor buttons for it, for example. The site has two news feeds, and when adding to each of them, you need to show your own tooltip. And the set of buttons may depend on the group in which the current user is a member. In total, when displaying the field, we need to get the context (user group and news feed number) and collect the values corresponding to this context.
The first candidate is this design:
field_id | parent_id | user_group | newsfeed_id | label | description | buttons
--------------------------------------------------------------------------------------------
1 | null | null | null | 'Текст' | 'Текст новости' | 'basic'
2 | 1 | 'admin' | null | null | null | 'full'
3 | 1 | null | 2 | null | 'Текст пресс-релиза'| null
4 | 3 | 'sekretarsha'| null | null | null | 'none'
field:
field_id | context_id | label | description | buttons
context:
context_id | parent_context_id
context_definition:
context_id | property | operator | value
context_id | property | operator | value
--------------------------------------------------
1 | 'reg_age' | > | 7776000
1 | 'group' | = | 'sekretarsha'
value_definition:
entity_type | entity_id | context_id | property | value
Answer the question
In order to leave comments, you need to log in
If it’s about the news text input block, then the easiest way is to add a TypeId to the model, and then store the NewsTypes table with the settings in the database in the form of serialized data (yes, at least json).
In general, trying to store business logic using structural features / database fields is still fun. I have experience. This leads to slowdowns and difficulties in checking / testing ...
Perhaps at the initial stage it will be easier to describe the business logic in code (a separate class) than to rush into the embrasure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question