Hi, Charlotte,
Can you run two separate queries, and then add the results together?
That way the first query can give you just those with dates, sorted by
the date in ascending order. The second query can be for results with
NULL date. If you add the two collections together, you will get an
array. If this works, it's probably the simplest way to do it.
Otherwise, you might need to sort on a function like COALESCE, which
will turn the NULL into a value that's after the highest value in your
database, for example:
Task.find_by_sql("Select * from tasks order by COALESCE(completed_at,
'2020-01-01')")
COALESCE is specific to MySQL so you need to check out the
documentation for whatever database you are using.
-Ana
On Jan 21, 3:01 pm, Charlotte <[email protected]> wrote:
> I have a query, that sorts the date in an ascending order.
> The date is optional, so there are NULL values.
> The NULL values are the ones on the top, rather than the results
> containing dates.
> How can I show the results in an ascending order, and the NULL values
> will be on the end of the list?
>
> Please do help, since I'm quite new in this.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---