I have the following Play Framework object (using Morphia for persistence) as part of a generic blogging application:
@Entity
public class Comment extends Model {
...
@Reference
@Indexed
public SiteUser commenter;
public static List<Comment> getLastCommentsByUsers(final List<SiteUser> users) {
final Query<Comment> query ds().createQuery(Comment.class);
query.field(commenter).hasAnyOf(users);
return query.asList();
}
}
SiteUser:
@Entity(noClassnameStored=true)
public class SiteUser extends AbstractUser {
public String realName;
}
AbstractUser:
public class AbstractUser extends Model {
@Indexed(value= IndexDirection.DESC, unique = true)
public String emailAddress;
@Required
public String password;
}
The method is supposed to getLastCommentsByUsers()return all user comments in the parameter users, but I always get empty Listback. The reason that there Commmentis a separate collection is the ability to get the last X by Commentcertain users through their associated Posts, which is not possible if it Commentis built into the collection Post.
Something is wrong with my request (if I should use something other than hasAnyOf), or is it a problem with displaying relationships - should I use it instead ObjectId?