java - foreign key query play! framework 2.+ ebean -
i'm new play framework , ebean orm.
basically, have 2 models 1 regusers other regids. in registration ids put many 1 relationship on field regusers. stating, if i'm not mistaken 1 user can have many registration ids.
regid model:
@entity public class regid extends model{ public static finder<long,regid> finder = new finder<long,regid>(long.class, regid.class); @id public long id; @manytoone public regusers regusers; public string regid; } reguser model:
@entity public class regusers extends model{ public static finder<long,regusers> find = new finder<long,regusers>(long.class, regusers.class); @id public long id; public string email; public string name; } a regid must have reguser, reguser not need have regid. 1 of views i'm trying show regusers have regid once, cannot figure out how this.
i got close querying regid table so:
list<regid> reg = regid.finder.where().findlist(); and querying reguser.name by:
@(regs: list[regid]) @for(reg <- regs){ <p>@reg.regusers.email</p> } but can't figure out how show distinct records. there way using ebean or need writ raw sql? appreciate help.
if add regids field regusers definition this:
@entity public class regusers extends model{ public static finder<long,regusers> find = new finder<long,regusers>(long.class, regusers.class); @id public long id; public string email; public string name; @onetomany(mappedby="regusers") public set<regid> regids; } you can query regusers have at least one regid this:
regusers.find.where().isnotnull("regids.id").findlist() if want find regusers exactly one regid need write custom sql indeed.
Comments
Post a Comment