玩框架2 ManyToMany关系

时间:2013-02-22 10:43:42

标签: playframework-2.0 ebean

我有两个班级:

public class Tag {
@Id
public int id;

@ManyToMany(cascade=CascadeType.ALL)
public static List<Article> articles;

public static Finder<Long, Tag> find = new Finder<Long, Tag>(Long.class, Tag.class);
}


public class Article {  
@Id
public int id;

@Constraints.Required
public String title;

@ManyToMany(cascade=CascadeType.ALL)
public static List<Tag> tags;

public static Finder<Long, Article> find = new Finder<Long, Article>(Long.class,     Article.class);

我需要获取文章作为参数的功能并返回与本文相关的标签列表

1 个答案:

答案 0 :(得分:0)

试试这个:

public List<Tag> findTagsByArticle(Article article) {
    return find.fetch("articles").where().eq("articles.id", article.id).findList();     
}

检查类似的question with answer

filterMany()被描述为in its API