I am trying to implement DBFlow in my Android Project. I have been able to create a table and add rows and columns to it. I have two columns, ID and Names. Now I want to retrieve the Names from the table and arrange it in descending order by ID. I found this example syntax in Github DBFlow page
SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_id, true)
.queryList();
SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_id, true)
.orderBy(Customer_Table.name, false)
.queryList();
But I am unable to under what "Customer_Table.customer_id" means in that code. When I try to put the method orderBy(), Android Studio suggests (NameAlias nameAlias, boolean) as the parameter. How do I added a NameAlias to my table? Can someone please help me with this?
When you implement DbFlow in your project it automatically builds a table class for each table model you have annotated with the @Table annotation.
i.e, if you have a table with name Customer then the corresponding class would be Customer_Table and if your table is User then the corresponding class would be User_Table.
Let this be your Customer table:
@Table
public class Customer extends BaseModel {
@Column
String customer_name;
}
If you want to order your results with customer name in Customer table, then use like this,
SQLite.select()
.from(table)
.where()
.orderBy(Customer_Table.customer_name, true)
.queryList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With