Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use JSON query operands in fields list #1347

Open
texonidas opened this issue Jun 2, 2020 · 0 comments
Open

Unable to use JSON query operands in fields list #1347

texonidas opened this issue Jun 2, 2020 · 0 comments

Comments

@texonidas
Copy link

texonidas commented Jun 2, 2020

Lithium Version: 1.0

$data = MyModel::all([
    'fields' => [
        'IFNULL(prices->\'$."1"\', prices->\'$."default"\') as MyModel.price',
    ],
])->data();

I'm trying to access a value of a json field in my field list (returns many results and processing serverside isn't very feasible because of speed concerns). I'm getting an error in /data/source/Database.php on line 680. It appears to be splitting all the field name values on '.' in order to sort them?

I have also tried 'MyModel.price' => 'IFNULL(prices->\'$."1"\', prices->\'$."default"\')' and received the same result.

To my knowledge there is no way to retrieve data from a JSON field within a query without specifying a path, which requires using the '$.field' notation. Is there a way for me to mark this as a calculated field and prevent this from happening? Alternately is there an official way to access JSON fields with li3, or to disable this "sorting" from occurring?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant