我的数据模型:
public class Tour extends Model {
@Id
public Integer id;
@ManyToOne
public Sport sport;
@OneToOne(mappedBy="genericTour")
FootballTour footballTour;
@OneToOne(mappedBy="genericTour")
TennisTour tennisTour;
public static Finder<Integer, Tour> find(){
return new Finder<Integer,Tour>(Integer.class,Tour.class);
}
}
public class FootballTour extends Model {
@Id
public Integer id;
@OneToOne
Tour genericTour;
public static Finder<Integer, FootballTour> find(){
return new Finder<Integer,FootballTour>(Integer.class,FootballTour.class);
}
}
我的行为(只是为了表明我正在获取“footballTour”):
public static Result getToursBySportTag(String sportTag){
Query query = Tour.find().fetch("sport").fetch("footballTour");
List<Tour> finedTours = query.where().eq("tag", sportTag).findList();
return ok(tours.render(finedTours));
}
在 scala 模板中,我想访问巡回赛的 footballTour 领域:
@(tours: List[Tour])
@main("Football tours") {
<h1>Football tours List</h1>
<dl>
@for(tour <- tours) {
<dt>
<a href="@routes.Application.tour(tour.id)">
@tour.footballTour.id
</a>
</dt>
}
</dl>
}
并在编译时出错:
[错误] 发现一个错误 [错误] {file:/C:/Users/pc/prog/}prog/compile:compile: C 编译失败 [信息] 将 1 个 Scala 源编译到 C:\Users\pc\prog\target \scala-2。9.1\classes... [错误] C:\Users\pc\prog\target\scala-2.9.1\src_managed\main\views\ html\tours.template.scala:37:类 Tour 中的变量 footballTour 不能访问ssed in models.Tour [error] """), display (Seq Any ),format.raw/ 8.11 /(""" - """), display (Seq Any ),format.raw/ 8. 35 /( “““ [错误]