I am playing around with GreenDAO and I think I like the way it works. I do not like to write SQL code, so this will help me avoid it ;)
But still, I think it really is very 'sql'-based thinking of how you set it up. Not sure if this is a bad thing (to know how things work), but I'd rather just say: here is my object! Store it! But I haven't found anything for this yet...
But ok, what I am doing is sort of the following: I have an object, let's say a bookshelve. I put some books on the shelve.
This would look something like:
class BookShelve {
List<Book> books;
void add(Book b) {
books.add(b);
}
}
BookShelve bs = new BookShelve();
Book b1 = new Book();
Book b2 = new Book();
Book b3 = new Book();
bs.add(b1);
bs.add(b2);
bs.add(b3);
ok, now I want to store this using GreenDAO. Do I need to use 'addToMany' for this? So:
Property bookDataProperty = bookData.addLongProperty("bookShelve").getProperty();
ToMany books = BookShelve.addToMany(bookData, bookDataProperty);
books.setName("Books");
and then do a:
bs.getBooks()
to get them? Or is there a better way?
I think it should be done like this, but I am not fully convinced yet.
ps: there may be typo's in the code above, I just wrote it here, haven't compiled it :)
Edit: This came up after I gave the 'answer' check:
so, to add books to a shelve, I need to:
b1.setBookShelve(bs.getId());
daoSession.insert(b1);
right?