I have these two classes
@DatabaseTable
public class User {
@DatabaseField(generatedId=true)
private int _id;
@DatabaseField
private String name;
@DatabaseField
private String password;
@DatabaseField(canBeNull = false, foreign = true, unique = true)
private Item item;
and
@DatabaseTable
public class Item {
@DatabaseField(generatedId=true)
private int _id;
@DatabaseField
private String name;
I would like to query a single user from the database using a platform since they are unique, how do I go about this?
I’m not sure what a “platform” is. To query for a
Userthat matches a particularItemyou would do something like:This returns a list of results. If there will be only one then you could do
It is a good pattern to define the column name using a
public final static String:Then your query can do:
Notice that although the actual field stored is an integer, the
eq(...)method is smart enough to take anitemand extract its id field from it.