Replies: 1 comment 2 replies
-
Just added a Not quite as flexible as a |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
I've have a field type that stores a value as JSON with the format:
With Craft 5 now using JSON and providing some useful methods for dealing with JSON I'd like to allow users to query these fields on a granular level like so:
The standard
Field::queryCondition
doesn't support this but support could be added in on a field by field basis.This is somewhat doable but I find myself having to go outside of Craft's built in methods like
jsonExtract
asField::valueSql
andField::getValueSql
make some assumptions about the JSON path that make this harder to implement.Solution
In my testing this could be solved by allowing a path to be passed to
valueSql
and then down togetValueSql
, falling back to current behaviour of using the first type inField::dbType()
.I've quickly put this together to illustrate where I pass the path into
valueSql
and then on togetValueSql
, falling back to the current behaviour.This then allows using the
jsonExtract
method which I can then use inqueryCondition
to achieve the query.Beta Was this translation helpful? Give feedback.
All reactions