Reputation: 3907
I am using Play framework with Ebean. I have two models, below are the code:
public class User extends Model {
@Id
public Long id;
public String name;
/* rest of attributes */
public static Finder<Long,User> find = new Finder<Long,User>(
Long.class, User.class
);
}
public class Admin extends Model {
@Id
public Long id;
@OneToOne
public User user;
/* rest of attributes */
public static Finder<Long,Admin> find = new Finder<Long,Admin>(
Long.class, Admin.class
);
}
When I do Logger.info(admin.user.name)
in Java, I can see the name of the admin. But when I pass the Java object to Scala using view render, if I do @admin.user.id
, I can still get the id, but if I do @admin.user.name
, I get nothing (with no error). I'm just wonder how can I access the name attribute from a joined table?
Upvotes: 1
Views: 479
Reputation: 3907
Problem solved. Before when I do the fetching, I did
Admin.find.where()
.ilike("user.name", "%" + filter + "%")
.orderBy("user."+sortBy + " " + order)
.findPagingList(pageSize)
.getPage(page);
After changing to
Admin.find.fetch("user", new FetchConfig().query())
.where()
.ilike("user.name", "%" + filter + "%")
.orderBy("user."+sortBy + " " + order)
.findPagingList(pageSize)
.getPage(page);
It successfully displayed instance variables on Scala.
Upvotes: 1