两列唯一约束ActiveAndroid [英] Two column unique constraint ActiveAndroid
问题描述
如何在ActiveAndroid中添加两列唯一约束?
我试图添加2.sql并增加数据库版本,但是它似乎没有正确更新(可能是因为我重新安装了该应用程序?)。无论如何,是否有办法添加一些注释,以便可以在ActiveAndroid中应用两列唯一约束?
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" />
推荐答案
使用@Column批注中的uniqueGroups属性。
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.
这篇关于两列唯一约束ActiveAndroid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!