3

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

Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64

1 Answers1

8

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.

John
  • 460
  • 1
  • 5
  • 18
mehdi
  • 912
  • 7
  • 20