New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One-to-many support. #25

Merged
merged 4 commits into from Apr 8, 2014

Conversation

Projects
None yet
4 participants
@Queatz
Copy link
Contributor

Queatz commented Feb 4, 2014

There are a few changes here.

  • Bidirectional relationships are handled internally, so the user doesn't have to mark one an inverse anymore or pay attention to that (this was causing lots of problems with one-to-many.)
    This is done by temporarily caching just the prior Entities that could induce the circular reference.
    In order to support this, the Primary Key is the first field to be filled when an Entity is loaded.
  • One-to-many support. This adds a List TypeMapping, however the only supported list is currently an Entity list.
  • Simple order by in DESC.
  • Close leaked cursor.

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

@ChristopheCVB

This comment has been minimized.

Copy link
Contributor

ChristopheCVB commented Apr 3, 2014

Wow ! You made it ?!

I'll test it tomorrow !

@ChristopheCVB

This comment has been minimized.

Copy link
Contributor

ChristopheCVB commented Apr 3, 2014

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

@Queatz

This comment has been minimized.

Copy link
Contributor

Queatz commented Apr 3, 2014

@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 roscopeco merged commit 24fd840 into roscopeco:master Apr 8, 2014

@roscopeco

This comment has been minimized.

Copy link
Owner

roscopeco commented Apr 8, 2014

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

@Queatz

This comment has been minimized.

Copy link
Contributor

Queatz commented Apr 8, 2014

Awesome, good to have it. :)

@akinadude

This comment has been minimized.

Copy link

akinadude commented Jul 11, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment