Android Oda Devamlılığı Kitaplığı ile çok fazla ilişki nasıl uygulanır?Android Oda Persistence Kütüphanesi ile çok fazla ilişki nasıl uygulanır?
Bir kullanıcı bir veya daha fazla aygıta sahip olabilir & Bir aygıt bir veya daha fazla kullanıcıya ait olabilir.
@Entity
public class User {
public @PrimaryKey Long id;
public String userName;
}
@Dao
public interface UserDao {
@Query("select * from user") List<User> getAllUsers();
@Query("select * from user where id = :id")
User getUserById(long id);
}
@Entity
public class Device {
public @PrimaryKey Long id;
public String name;
}
@Dao
public interface DeviceDao {
@Query("select * from device")
List<Device> getAllDevices();
}
@Entity
public class UserDevice {
public String userId;
public String deviceId;
}
@Dao
public interface UserDeviceDao {
// List all devices by userId
// List all users by deviceId
}
Kodunuz, ilişkiyi temsil eden "UserDevice" ile bir M: N ilişkisi uygular gibi görünüyor. – CommonsWare