Consider I have 3 classes User, Address, Location
class Address {
public String street;
public String state;
public String city;
@ColumnInfo(name = "post_code")
public int postCode;
@Embedded(prefix = "home_")
public Location homeLocation;
@Embedded(prefix = "office_")
public Location officeLocation;
}
class Location{
public long lat;
public long lng;
}
@Entity
class User {
@PrimaryKey
public int id;
public String firstName;
@Embedded(prefix = "addr_")
public Address address;
}
How should i write the query to get the users whose home location is between certain latitude and longitude boundary ?
Ex: If i want to find all users whose home location is between these two points Location1(13.135795,77.360348) & Location2(12.743639, 77.901424). My query would look something like this -
select * from User where address.homelocation.lat < :l1_latitude && address.homelocation.lat > l2_latitude && address.homelocation.lng > :l1_longitude && address.homelocation.lng < :l2_longitude
If i have to use prefix in the embedded location from my understanding, correct me if am wrong, all the fields inside address will get appended with prefix. So i can query city as addr_city and if i have to query lat inside the homeLocation then will it become addr_home_lat ?
Is nested embedded objects permitted in room database? If yes then how do i query the nested embedded objects?
Need some help here. Thank you.