docs icon indicating copy to clipboard operation
docs copied to clipboard

Using Json as an example for custom datatype can be misleading

Open MolbioUnige opened this issue 1 year ago • 5 comments

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.

MolbioUnige avatar Aug 21 '24 12:08 MolbioUnige

Isn't this enough? https://book.cakephp.org/4/en/orm/saving-data.html#saving-complex-types

LordSimal avatar Aug 21 '24 13:08 LordSimal

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.

jamisonbryant avatar Aug 21 '24 13:08 jamisonbryant

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

LordSimal avatar Aug 21 '24 13:08 LordSimal

There is the PointType example already, and yes @LordSimal the saving complex type explanation is enough

MolbioUnige avatar Aug 21 '24 13:08 MolbioUnige

A link "see Saving complex datatype" at some place along with @jamisonbryant suggestion about stating that Json is natively supported could be useful.

MolbioUnige avatar Aug 21 '24 13:08 MolbioUnige

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

dereuromark avatar Nov 18 '24 12:11 dereuromark

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

github-actions[bot] avatar Mar 27 '25 00:03 github-actions[bot]

@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 avatar Mar 27 '25 14:03 jamisonbryant

@jamisonbryant Yes, of course

MolbioUnige avatar Mar 27 '25 14:03 MolbioUnige

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.

jamisonbryant avatar Mar 27 '25 19:03 jamisonbryant

I just made a PR about this.

MolbioUnige avatar Apr 08 '25 11:04 MolbioUnige

https://github.com/cakephp/docs/pull/8012

dereuromark avatar Apr 08 '25 12:04 dereuromark