Object ReferencesΒΆ

Dari supports querying relationships using the field/subfield path notation in where methods. The following models demonstrate the use case of finding all activities for a particular user. The Activity.activityUser field is of type User.

 public class Activity extends Record
    @Indexed private Date activityDate;
    @Indexed private User activityUser;
    @Indexed private String groupLead;

     // Getters and Setters...

 public class User extends Record
    @Indexed private String name;

    // Getters and Setters...

There are two ways to find activities by a specific user. You can first query for the user, and then query for activites by that user.

// Get the user
User user = Query.from(User.class).where("name = 'John Smith'").first();
// Get the user's list of activites
List<Activity> activities = Query.from(Activity.class).where("activityUser = ?", user).selectAll();

A second, more efficient way, is to use a single query that incorporates path notation.

List<Activity> activities = Query.from(Activity.class).where("activityUser/name = 'John Smith'").selectAll();