Cyril N.
Cyril N.

Reputation: 39879

Ebean Search where ManyToMany is empty?

With PlayFramework I'm trying to list all the items where there is no ManyToMany items associated with my model, how can I do that ?

Here's my structure :

User
    @ManyToMany
    List<Section> sections;

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

Section
    Integer year;
    @ManyToMany
    List<User> users;

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

Upvotes: 2

Views: 1220

Answers (2)

Miguel A. Carrasco
Miguel A. Carrasco

Reputation: 1399

You need to do this:

String q="find * fetch sections where sections.id is null"

Ebean.createQuery(User.class,q).findList();

This will create a left outer join query, the find.where().IsNull("sections") doesn't work.

Upvotes: 4

biesior
biesior

Reputation: 55798

Try these:

find.where().eq("sections", null).findList();

or

find.where().isNull("sections").findList();

Sorry it's from top of my head, can't verify it now.

Upvotes: 2

Related Questions