roscopeco / ormdroid

ORMDroid is a simple ORM persistence framework for your Android applications.
http://roscopeco.github.io/ormdroid/
Apache License 2.0
86 stars 24 forks source link

One-to-many support. #25

Closed Queatz closed 10 years ago

Queatz commented 10 years ago

There are a few changes here.

There are a few white-space removals, I apologize for that. My editor auto trims.

ChristopheCVB commented 10 years ago

Wow ! You made it ?!

I'll test it tomorrow !

ChristopheCVB commented 10 years ago

Can you provide a full example usage of this new feature ?

Queatz commented 10 years ago

@ChristopheCVB it's a simple implementation and not very smart, so I'd only use it for small projects. For small projects it should work great, though.

Basic usage is like this:

Person.java

class Person extends Entity {
    public String name;

    @Column(inverse = "person")
    public ArrayList<Hobby> hobbies;
}

Hobby.java

class Hobby extends Entity {
    public String type;
    public Person person;
}

And then you would just use it like normal:

Person person = Entity.query(Person).where(eql("name", "Christ")).execute();

for(Hobby hobby : person.hobbies)
    Log.d(TAG, "Hobby found: " + hobby.type);

Hope this helps!

roscopeco commented 10 years ago

This is now in master. Thanks again @Queatz and sorry it took so long!

Queatz commented 10 years ago

Awesome, good to have it. :)

akinadude commented 10 years ago

it seems to me this feature doesn't work or may be I do something wrong. Question and code snippets here http://stackoverflow.com/questions/24697824/ormdroid-one-to-many-relationship