문제

Does GreenDao supports unique constraint on multiple columns? Equivalent of the following:

create table projects (
  _id integer primary key autoincrement,
  project_type text,
  name text,
  unique (project_type, name)
);
도움이 되었습니까?

해결책

Yes, it supports.

Create an index with all the properties and make it unique.

Index indexUnique = new Index();
indexUnique.addProperty(project_type);
indexUnique.addProperty(name);
indexUnique.makeUnique();
projectsEntity.addIndex(indexUnique);

Source

다른 팁

As for version 3.2.0, you can declare multiple indexes in the Entity declaration :

@Entity(
    indexes = {
       @Index(value = "column1,column2,column3", unique = true)
    }
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top