我有实体MySurvey
,而MySurvey
的列名为answers
,如下所示:
我的调查
@Entity(tableName = "my_survey")
data class MySurvey(@PrimaryKey var _id: String = "",
var created_at: String = "",
var conducted_at: String? = "",
var cancellation_reason: String?,
var enumeratorId: String = AppPreferences.getString(Enumerator_Id, "default"),
@Embedded(prefix = "basic_") var survey: SurveyBasic,
@Embedded(prefix = "location_") var location: SurveyLocationBasic?,
var ended_at: String? = "",
var status: MySurveyStatus = MySurveyStatus.OFFLINE,
@Embedded var stats: Stats?,
var uploaded: Boolean,
var answers: List<AnswersResponse>? = listOf()
)
MySurveyDAO
@Dao
interface MySurveyDAO {
@Insert(onConflict = REPLACE)
fun insert(mySurvey: MySurvey): Long
@Insert(onConflict = REPLACE)
fun insert(savedSurvey: List<MySurvey>)
}
有一个列表屏幕,该屏幕从没有MySurvey
的API中提取answers
个数组。当基于MySurvey
获取特定ID
并且具有answers
对象的详细信息屏幕时。我使用onConflict = REPLACE
策略在数据库中进行了更新。效果很好,但是当我恢复列表屏幕时,数据库的所有记录都有answers
列为NULL
,这是由于REPLACE
策略所致。
是否有一种方法可以添加仅
REPLACE
列为IF IT IS NOT NULL
的条件?