Two column unique constraint ActiveAndroid

1k views Asked by At

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" />

enter image description here

1

There are 1 answers

1
mehdi On BEST ANSWER

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.