docs
docs copied to clipboard
Using Json as an example for custom datatype can be misleading
Issue Description
Using Json as an example for the custom type might make people think that Cakephp doesn't handle json natively. I found it a bit confusing. Instead, having a section explaining how to use the native JsonType, like the EnumType, would be nice.
Isn't this enough? https://book.cakephp.org/4/en/orm/saving-data.html#saving-complex-types
I think what @MolbioUnige might be referring to is that Cake now ships with the JsonType, whereas I don't believe that was always the case. So, users might read these docs and create their own JsonType, not realizing that Cake already has one and their efforts were redundant. At $MYJOB we ran into this ourselves in a recent project.
I think documenting EnumType in place of JsonType (perhaps with a notice that JsonType is already part of Cake) is a good choice because many PHP8 users, myself included, are eager to see an example of its usage.
Then it would be best if we'd come up with another, not so straight forward example of a custom Database Type to replace the currently redundant JsonType
There is the PointType example already, and yes @LordSimal the saving complex type explanation is enough
A link "see Saving complex datatype" at some place along with @jamisonbryant suggestion about stating that Json is natively supported could be useful.
You can also invent a custom type, e.g. YearType or alike: https://github.com/dereuromark/cakephp-shim/blob/04aa7bac781475c94a023ee9f47e4bac3005d56c/src/Database/Type/YearType.php
This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days
@MolbioUnige would you like to make a docs PR to address this issue? I am happy to generate a quick custom Type class that you can use as an example.
@jamisonbryant Yes, of course
The YearType that @dereuromark linked above looks like a good candidate.
But if this is ambiguous, I can share my JsonCollectionType which just converts a flat JSON array into a CollectionInterface.
I just made a PR about this.
https://github.com/cakephp/docs/pull/8012