Two column unique constraint ActiveAndroid

随声附和 提交于 2019-12-12 12:32:22

问题


How can I add two column unique constraint in ActiveAndroid? I tried to add 2.sql and increase DB version, but it doesnt seem to be updated correctly (probably because I reinstall the app?). Anyway, is there are way to add some annotation on which I can apply two column unique constraint in ActiveAndroid ?

<meta-data android:name="AA_DB_NAME" android:value="Diggecard.db" />
<meta-data android:name="AA_DB_VERSION" android:value="2" />


回答1:


Use the uniqueGroups property in the @Column annotation.

Make sure both columns have the same group name and they both must define the constraint.

@Column(uniqueGroups = {"groupName"}, onUniqueConflicts = {ConflictAction.FAIL})

@Column(uniqueGroups = {"groupName"}, onUniqueConflicts = {ConflictAction.FAIL})

There is actually a sample included here, in the source.



来源:https://stackoverflow.com/questions/30868563/two-column-unique-constraint-activeandroid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!