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

How to set ID? #21

Closed
HDANILO opened this Issue Apr 11, 2015 · 12 comments

Comments

Projects
None yet
3 participants
@HDANILO

HDANILO commented Apr 11, 2015

I can see a getID method, but I want to set ID prior to saving, its important because the local DB must have the same ID's as the server, so, server generates them, not the local DB.

@dco5

This comment has been minimized.

Show comment
Hide comment
@dco5

dco5 Apr 11, 2015

You can use the property ID from the server if you need to, I think rushorm uses rush_id, so if you want to set the id from server just use the setId(int serverId) and to get it you have to use something like getServerID() because getId returns rush_id. I had that same question when I was doing my app but I had no problem at all using the serverId. That is why I started using RushOrm, i was trying with SugarORM and it was a big conflict because you can not use the property ID, unlike with RushORM.

dco5 commented Apr 11, 2015

You can use the property ID from the server if you need to, I think rushorm uses rush_id, so if you want to set the id from server just use the setId(int serverId) and to get it you have to use something like getServerID() because getId returns rush_id. I had that same question when I was doing my app but I had no problem at all using the serverId. That is why I started using RushOrm, i was trying with SugarORM and it was a big conflict because you can not use the property ID, unlike with RushORM.

@HDANILO

This comment has been minimized.

Show comment
Hide comment
@HDANILO

HDANILO Apr 11, 2015

@dco5 Same problem, just tossed Sugar out, trying Rush, seems promising, but, what if I use some one-to-many relation? Can I force Rush to make those relations based on my serverID in a simple way?

HDANILO commented Apr 11, 2015

@dco5 Same problem, just tossed Sugar out, trying Rush, seems promising, but, what if I use some one-to-many relation? Can I force Rush to make those relations based on my serverID in a simple way?

@dco5

This comment has been minimized.

Show comment
Hide comment
@dco5

dco5 Apr 11, 2015

I had one-to-many relation too, with no problems at all. I never search for the children directly, but if you have to search directly for them you can put the parent server id, and search for the children with parent server id

dco5 commented Apr 11, 2015

I had one-to-many relation too, with no problems at all. I never search for the children directly, but if you have to search directly for them you can put the parent server id, and search for the children with parent server id

@HDANILO

This comment has been minimized.

Show comment
Hide comment
@HDANILO

HDANILO Apr 11, 2015

I'm using @RushList to do the one-to-many, they'll automatically use the rush_id which is private, am I right? This will reflect too, because the "children" are also persisted on the server and they should not carry the rush_id or a fk related to rush_id.

If he could add the setID it would be much much easier to handle, seems pretty straight forward to implement too...

HDANILO commented Apr 11, 2015

I'm using @RushList to do the one-to-many, they'll automatically use the rush_id which is private, am I right? This will reflect too, because the "children" are also persisted on the server and they should not carry the rush_id or a fk related to rush_id.

If he could add the setID it would be much much easier to handle, seems pretty straight forward to implement too...

@HDANILO

This comment has been minimized.

Show comment
Hide comment
@HDANILO

HDANILO Apr 11, 2015

Done some analising, seems like its a matter of adding getID on RushMetaData and the getID on the RushCore, and reflect that also on RushObject and Rush interface.

HDANILO commented Apr 11, 2015

Done some analising, seems like its a matter of adding getID on RushMetaData and the getID on the RushCore, and reflect that also on RushObject and Rush interface.

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 11, 2015

Owner

Have you had a look at

RushCore.getInstance().deserialize();

It is dependent on your sever giving you your data in json format that matches your java objects, but you can pass in the name of the id field in the json then it will be used in the database instead of creating it's own id. Might be what your looking for.

https://github.com/Stuart-campbell/RushCore/blob/master/src/main/java/co/uk/rushorm/core/RushCore.java#L249-276

Owner

Stuart-campbell commented Apr 11, 2015

Have you had a look at

RushCore.getInstance().deserialize();

It is dependent on your sever giving you your data in json format that matches your java objects, but you can pass in the name of the id field in the json then it will be used in the database instead of creating it's own id. Might be what your looking for.

https://github.com/Stuart-campbell/RushCore/blob/master/src/main/java/co/uk/rushorm/core/RushCore.java#L249-276

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 11, 2015

Owner

Also searching for children is now possible with

RushSearch.whereChildOf(Rush parent, Sting field);

Thanks

Owner

Stuart-campbell commented Apr 11, 2015

Also searching for children is now possible with

RushSearch.whereChildOf(Rush parent, Sting field);

Thanks

@HDANILO

This comment has been minimized.

Show comment
Hide comment
@HDANILO

HDANILO Apr 11, 2015

@Stuart-campbell To create the object with proper ID I must give a JSON to be deserialized? Dont you think its a work around, and those are bad some times? my server already uses its protocol to comunicate with the application, and I really dont want to change that.

If you want, I can do a pull request fixing the setID, making my life, and I bet, many other people life better, ofc, if there isnt a problem with that!

I bet the search children uses the rush_id to go through the children, and thats exactly what I must avoid if I follow the suggestion from @dco5 and create my own ID, since at any time, the local DB can be wiped, and sync'ed again from the server, this will for sure mess things up. It could be better, if I could edit it with setID that could be even easier because all would work without the need of putting extra fields(IDs) and making the one to many relation myself hard coded

HDANILO commented Apr 11, 2015

@Stuart-campbell To create the object with proper ID I must give a JSON to be deserialized? Dont you think its a work around, and those are bad some times? my server already uses its protocol to comunicate with the application, and I really dont want to change that.

If you want, I can do a pull request fixing the setID, making my life, and I bet, many other people life better, ofc, if there isnt a problem with that!

I bet the search children uses the rush_id to go through the children, and thats exactly what I must avoid if I follow the suggestion from @dco5 and create my own ID, since at any time, the local DB can be wiped, and sync'ed again from the server, this will for sure mess things up. It could be better, if I could edit it with setID that could be even easier because all would work without the need of putting extra fields(IDs) and making the one to many relation myself hard coded

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 11, 2015

Owner

No I wouldn't suggest turning into json just to set the id. Was pointing it out as you may have already been deserializing with something like gson so would have been an easy switch.

I think I do understand your use case. Basically you need what the deserialize method does but without using it.

The rush_id is really a "final" property so I think adding a registerObjectWithId method might make more sense than setId.

Although if I add that to RushCore it would be easy for you to add setId to your object that would just call that method.

I should be able to look at that tomorrow.

Thanks

Owner

Stuart-campbell commented Apr 11, 2015

No I wouldn't suggest turning into json just to set the id. Was pointing it out as you may have already been deserializing with something like gson so would have been an easy switch.

I think I do understand your use case. Basically you need what the deserialize method does but without using it.

The rush_id is really a "final" property so I think adding a registerObjectWithId method might make more sense than setId.

Although if I add that to RushCore it would be easy for you to add setId to your object that would just call that method.

I should be able to look at that tomorrow.

Thanks

@HDANILO

This comment has been minimized.

Show comment
Hide comment
@HDANILO

HDANILO Apr 11, 2015

@Stuart-campbell Thank you very much, that registerObjectWithId would work too!

HDANILO commented Apr 11, 2015

@Stuart-campbell Thank you very much, that registerObjectWithId would work too!

Stuart-campbell added a commit that referenced this issue Apr 12, 2015

Added Auto @RushIgnore on final params #18 and register object method…
…s for How to set ID? #21. Also RushListField which allows for loading children in a paging way.
@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 12, 2015

Owner

Hi,

I have added registerObjectWithId method. So if you call that after creating your objects from your server calling save will create or updated them based on the id you set.

https://github.com/Stuart-campbell/RushCore/blob/master/src/main/java/co/uk/rushorm/core/RushCore.java#L367-374

Cheers

Owner

Stuart-campbell commented Apr 12, 2015

Hi,

I have added registerObjectWithId method. So if you call that after creating your objects from your server calling save will create or updated them based on the id you set.

https://github.com/Stuart-campbell/RushCore/blob/master/src/main/java/co/uk/rushorm/core/RushCore.java#L367-374

Cheers

@Stuart-campbell

This comment has been minimized.

Show comment
Hide comment
@Stuart-campbell

Stuart-campbell Apr 12, 2015

Owner

Added in v1.1.3

Owner

Stuart-campbell commented Apr 12, 2015

Added in v1.1.3

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