# |
Dec 28th 2018, 12:55 |
G00DSP33D |
So we dynamically add those validation rules in the beforeValidate. This allowed us to validate field values that are serialized into JSON later on. |
# |
Dec 28th 2018, 12:54 |
G00DSP33D |
Our approach: in beforeValidate we check the contents of the field Page.type. Let's say that it contains "product_page". In a CakePHP Config we kept a list of "dynamic fields" per page type, and their respective validation rules. |
# |
Dec 28th 2018, 12:53 |
challgren |
If you want tha ability to sort or filter |
# |
Dec 28th 2018, 12:52 |
challgren |
You may need to define those fields even if they are unnecessary for every record |
# |
Dec 28th 2018, 12:51 |
challgren |
I run an app that integrates with QBO but I dont store dynamic data in JSON |
# |
Dec 28th 2018, 12:51 |
G00DSP33D |
For example, our light approach doesn't allow us to sort products by price for example (unless we jump through a lot of hoops). |
# |
Dec 28th 2018, 12:51 |
challgren |
You could define a custom validation rule but Im not very familiar with it |
# |
Dec 28th 2018, 12:50 |
G00DSP33D |
Since we are now upgrading to 3.x, we're left wondering whether there are better ways to handle this light "Entity-Atribute-Value" setup. |
# |
Dec 28th 2018, 12:49 |
G00DSP33D |
So in CakePHP 2.x we used a TEXT field in the DB to store these "dynamic" properties. Depending on the page type, we dynamically added validation rules inthe beforeValidate callback. |
# |
Dec 28th 2018, 12:48 |
G00DSP33D |
Our CMS has a simplified take on the EAV pattern for storing dynamic data about webpage. A product page will have different data fields (price, weight, etc.) compared to a blog post (intro txt, etc.). |
# |
Dec 28th 2018, 12:47 |
challgren |
Like how so? |
# |
Dec 28th 2018, 12:47 |
G00DSP33D |
Thanks challgren for your suggestion. This behaviour is a great take on serializing JSON data, but we're looking for something more advanced. |
# |
Dec 28th 2018, 11:50 |
challgren |
@g00dsp33d look into https://github.com/dereuromark/cakephp-tools/blob/master/docs/Behavior/Jsonable.md |
# |
Dec 28th 2018, 11:06 |
G00DSP33D |
Any help / tips / pointers would be much appreciated! |
# |
Dec 28th 2018, 11:06 |
G00DSP33D |
In 3.x we're looking at the complex data types feature to help us, but we're unsure about 2 things. Should we follow our previous logic for validation or is there a better way? And is there any way in 3.x to query the database and search for a specific field value that is stored as a JSON string? |
# |
Dec 28th 2018, 11:06 |
birdy247 |
it was not setting ->useImmutable() |
# |
Dec 28th 2018, 11:06 |
birdy247 |
Ok, @dereuromark @steinkel it was our own datatype that had the issue |
# |
Dec 28th 2018, 11:04 |
G00DSP33D |
If validation was successful, we then took all the dynamic fields, apply json_encode() and store the data in the big TEXT field as a JSON string. |
# |
Dec 28th 2018, 11:03 |
G00DSP33D |
Our system was developed in 2.x and during this holiday season we're finally taking the plunge into 3.x. In 2.x we used a TEXT field in the DB to store dynamic field data as a JSON string. In order to ensure validation, we collected individual fields separately in the form. If a dynamic field was found in the form, we would dynamically add the necessary validation rules, so each field was validated. |
# |
Dec 28th 2018, 11:00 |
G00DSP33D |
Hi all, great to be here amongst fellow CakePHP devs! I have a quick question about validating complex data types (JSON) in CakePHP 3.x as we are in the middle of a migration of our CMS system. Anybody care to give some advice / pointers? |
# |
Dec 28th 2018, 10:53 |
birdy247 |
Think I have found it |
# |
Dec 28th 2018, 10:52 |
slackebot |
<birdy247> |
# |
Dec 28th 2018, 10:52 |
birdy247 |
Hmmm |
# |
Dec 28th 2018, 10:51 |
steinkel |
let me know, the plugin should not be dealing with that AFAIR |
# |
Dec 28th 2018, 10:50 |
birdy247 |
to pin this down to the plugin |
# |
Dec 28th 2018, 10:50 |
birdy247 |
ill try in my app |
# |
Dec 28th 2018, 10:49 |
dereuromark |
also detects nullables etc (made it possible for me to see and remove some of the bad nullables in the db) |
# |
Dec 28th 2018, 10:49 |
dereuromark |
tip: use Ide helper to annotate, it will detect the types and make it all visible per entity |
# |
Dec 28th 2018, 10:49 |
birdy247 |
its a getRequest |
# |
Dec 28th 2018, 10:48 |
birdy247 |
@steinkel know of any reason why my entities would not be using immutable dateTimes |
# |
Dec 28th 2018, 10:48 |
dereuromark |
then they might switch the config or manually do sth here |
# |
Dec 28th 2018, 10:48 |
birdy247 |
FYI, this is the cakeDC/API that is handling the request |
# |
Dec 28th 2018, 10:48 |
birdy247 |
but this was never an issue before |
# |
Dec 28th 2018, 10:47 |
birdy247 |
and I can see why |
# |
Dec 28th 2018, 10:47 |
nayakvradhit |
Ok sure thank you for your approach |
# |
Dec 28th 2018, 10:47 |
birdy247 |
What led me to investigate was something else is broken |
# |
Dec 28th 2018, 10:47 |
birdy247 |
I dont believe it was always like this |
# |
Dec 28th 2018, 10:47 |
dereuromark |
for me its frozenTime then |
# |
Dec 28th 2018, 10:47 |
dereuromark |
interesting |
# |
Dec 28th 2018, 10:45 |
birdy247 |
bootstrap |
# |
Dec 28th 2018, 10:45 |
slackebot |
<birdy247> |