Play Framework 2.0从模板访问外键对象

时间:2012-11-07 11:02:02

标签: templates foreign-keys playframework-2.0 ebean

我有2个与ManyToOne连接相连的Ebean模型。

@Entity
public class Interview extends Model {
   @Id
   Long id;
   @ManyToOne(cascade = CascadeType.MERGE)
   public User user;
   ....
}

@Entity
public class User extends Model {
   @Id
   public Long id;
   @Email
   @Required
   @Column(unique=true)
   public String email;
   @Required
   public String name;
   public String department;
   public String phone;
....
}

当尝试通过Interview实例从Scala模板访问User类字段时,我只能访问id字段,但其他人返回空字符串。 这是模板:

@(interviewsList[Interview])
....
<table>
.....
    @for(i <- interviewsList) {
     <tr>
            <td>@i.user.name</td> // EMPTY, while changing to @i.user.id returns an id
            <td>@i.date.format("dd MMM yyyy")</td>
         </tr>
     }
 </table>

有没有办法在不使用Finder的情况下访问其他字段?

0 个答案:

没有答案