Using ORMLite for Android, I need to build a query that returns orders by order id or by customer name. Please consider the following class declarations:
@DatabaseTable(tableName = "order")
public class Order {
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField(foreign = true, canBeNull = false, foreignAutoRefresh = true, columnName = "customer_id")
private Customer customer;
// default constructor, getters and setters...
}
@DatabaseTable(tableName = "customer")
public class Customer {
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField
private String name;
// default constructor, getters and setters...
}
The raw SQL I'm looking for would be something like this:
SELECT
o.*
FROM
order o
JOIN customer c on
o.customer_id = c.id
WHERE
(o.id = ?) OR (c.name = ?)
What is the best way to do this using ORMLite?
ORMLite now supports simple join queries.
So your query would look something like:
No, JOINs are supported in ORMLite https://stackoverflow.com/a/7320091/323128 However, this reference will give a vision how to complete your task