0

I have the model Job and Job model have field additional_data. Here additional_data column is stored as json data type and have field like "priority". I want to order jobs table entries based on additional_data's "priority" field value. I have code like following but it's not working. I need to order using ORM not by raw sql.

@jobs = Job.all.order('additional_data['priority'] asc')
2

1 Answer 1

0

This post is already 4 months old but maybe this can still make someone happy. You could do something like this.

@jobs = Job.all
.select('*, JSON_EXTRACT(additional_data, "$.priority") AS priority')
.order('priority asc')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.