New to ActiveAndroid (and overall to android database). I read their documentation, but i have one problem.
I have Route.class and LatLngPosition.class. The Route is made of more LatLngPosition nodes.
So my implementation is:
@Table(name="Route")
public class Route extends Model {
@Column(name="Name")
private String name;
@Column(name="Time")
private MyTime time;
public Route(String name, MyTime time) {
super();
this.name = name;
this.time = time;
}
public Route(){
super();
}
public List<LatLngPosition> getLatLngList(){
return getMany(LatLngPosition.class, "Route");
}
...
}
And my LatLngPosition class:
@Table(name="LatLng")
public class LatLngPosition extends Model {
@Column(name = "Latitude")
double latitude;
@Column(name = "Longitude")
double longitude;
@Column(name = "Route", onUpdate = Column.ForeignKeyAction.CASCADE, onDelete = Column.ForeignKeyAction.CASCADE)
Route route;
public LatLngPosition(double latitude, double longitude, Route route) {
super();
this.latitude = latitude;
this.longitude = longitude;
this.route = route;
}
public LatLngPosition(){
super();
}
...
}
I save some data to test if everything works:
route1 = new Route("first", new MyTime(1,1,10,10));
LatLngPosition pos1 = new LatLngPosition(10,10, route1);
LatLngPosition pos2 = new LatLngPosition(10,15, route1);
pos1.save();
pos2.save();
route1.save();
And then why trying to get it back from database:
Route route = Route.load(Route.class, 1);
I can call route.getName()
, and it will return name properly. But when i call route.getLatLngList()
, i get nothing, size of list is 0.
Why this don't work? Am I implementing right way 1-N relation?
Aucun commentaire:
Enregistrer un commentaire