Querying nodes


(Mike Peritore) #1

I have an event node that has a start_date. For my event index page, I’d like
to sort the events by start_date DESC. Does anyone have an example as to how
I might achieve this? I’m sure it is probably dead simple - hopefully, I’m just missing
the obvious! Loving this CMS!


(Aaron Russell) #2

Hi there. Custom fields are stored using the Postgres Jsonb datatype, under a single field called field_store. Best to refer to the postgres docs for tricks of the trade when querying jsonb data.

In your case, you’ll want something lilke this:

Event.all.order("field_store->>'start_date' DESC")

(Mike Peritore) #3

Thanks @aaron! I should have known better. This worked as advertised :thumbsup: