I want to implement android ROOM to my project. But I can not solve one-to-one relation between Order(customer_id) and Customer(id).
Is it possible to fill customer (@Ignore protected Customer customer) field in OrderDao interface?
I can solve only java codes. Is there any other methods?
// Customer.java
@Entity (tableName = "t_customer")
public class Customer {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
protected String mId;
@ColumnInfo(name = "name")
protected String mName;
}
// Order.java
@Entity(tableName = "t_order",
foreignKeys = {
@ForeignKey(entity = Customer.class,
parentColumns = "id",
childColumns = "customer_id",
onDelete = SET_NULL) }
public class Order {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
protected String mId;
@ColumnInfo(name = "description")
protected String mDescription;
@ColumnInfo(name = "customer_id")
protected String mCustomerId;
@Ignore
**protected Customer customer;**
//....
}
//OrderDao.java
@Dao
public interface OrderDao {
@Query("SELECT * from t_order ORDER BY id DESC")
LiveData<List<Order>> listByIds();
@Query("SELECT * from t_order WHERE id = :id LIMIT 1")
LiveData<Order> readById(long id);
//....
}