DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

[3.0.0-beta1] Specifying multiple columns in the .orderBy

Open andrewpmoore opened this issue 10 years ago • 8 comments

Previously I'd do something like this:

.orderBy("first_name, last_name")

but now with 3.0.0-beta1 I can't seem to find a way to handle multiple columns (or maybe the documentation needs adding to)

andrewpmoore avatar Dec 29 '15 13:12 andrewpmoore

would I do

.orderBy(Model_Table.first_name) .orderBy(Model_Table.last_name)

instead?

andrewpmoore avatar Dec 30 '15 08:12 andrewpmoore

Another issue potentially, is how do you cast an item in the order by. I'm wanting to cast a value into an integer and used to be able to use the "cast" function in sqlite but I'm not sure how to do that now.

andrewpmoore avatar Dec 30 '15 12:12 andrewpmoore

There is a new function that has been added:

orderByAll(List orderBies)

I didn't have the chance to test it yet but looking at its definition, it seems pretty clear that it's the new way of handling multiple columns.

eboissonneault avatar Dec 30 '15 13:12 eboissonneault

Thanks, that sound good, but I can't think how to call it. The Class OrderBy is private when trying to create a new OrderBy object

andrewpmoore avatar Dec 30 '15 14:12 andrewpmoore

Mutli orderbies also seems to work

.orderBy(1) .orderBy(2)

looking at the generated query

andrewpmoore avatar Dec 30 '15 14:12 andrewpmoore

@andrewpmoore I had problems trying that in previous versions. The order of the order Bies was randomly changing. I don't think it was intended to respect the order of function calls.

eboissonneault avatar Dec 30 '15 14:12 eboissonneault

@andrewpmoore You can instantiate a new OrderBy object using these static functions: OrderBy.fromProperty or OrderBy.fromNameAlias.

eboissonneault avatar Dec 30 '15 15:12 eboissonneault

Thanks Eric On 30 Dec 2015 3:06 p.m., "Eric Boissonneault" [email protected] wrote:

@andrewpmoore https://github.com/andrewpmoore You can instantiate a new OrderBy object using these static functions: OrderBy.fromProperty or OrderBy.fromNameAlias.

— Reply to this email directly or view it on GitHub https://github.com/Raizlabs/DBFlow/issues/518#issuecomment-168016378.

andrewpmoore avatar Dec 30 '15 19:12 andrewpmoore