Last active
June 18, 2017 11:54
-
-
Save mcatta/ce71597b59b7fc8975d73c0d8186b99f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Table(database=MyLibrary.class) | |
public class Book extends BaseModel { | |
@PrimaryKey(autoincrement = true) | |
int id; | |
@Column | |
String title; | |
@Column | |
int pages; | |
// Authors | |
List<Author> authors; | |
@OneToMany(methods = OneToMany.Method.ALL, variableName = "authors") | |
public List<Author> oneToManyAuthors() { | |
if (authors == null) { | |
authors = SQLite.select() | |
.from(Author.class) | |
.where(Author_Table.book_id.eq(id)) | |
.queryList(); | |
} | |
return authors; | |
} | |
Override | |
public boolean save() { | |
boolean res = super.save(); | |
if (authors != null) { | |
for (Author s : authors) { | |
s.setBook(this); | |
s.save(); | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment