-
Notifications
You must be signed in to change notification settings - Fork 583
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 #60
Comments
I'm want understand how to make relationship one-to-many too. I try |
ArrayList or other collections aren't supported yet. You could define your relationship like this example: http://satyan.github.io/sugar/creation.html#why |
I'm not sure based on the docs posted how to create a one to many relationship. Could you elaborate? |
I've hit this roadblock also. Struggling with this one! |
Any chance of this being supported soon? Or does anyone recommend any other ORM for Android? |
Here’s an example: Say you have two classes Author and Book. An Author can have many books. class Book{
String name;
Author author;
}
class Author{
String name;
public List<Book> getBooks(){
return Book.find(Book.class, "author = ?", new String{author.getId()})
}
} You can achieve the one to many relationship like this. |
Many to many is slightly tricky. You could create a LinkerClass similar to the link table in database, and use that to link the two objects. eg: Book where AuthorBooks would be class AuthorBooks{
Author author;
Book book;
} you can fetch in a similar style then: List<AuthorBooks> authorBooks = AuthorBooks.find(AuthorBooks.class, “author = ?”, author.getId()); This would have the list of books. It’s a round about approach.. but so far there’s no direct support for many to many relationship. |
Is this being worked on currently? |
Sugar does not handle many to many relationship for you currently. You'd have to manage the relationship yourself using an approach suggested above #60 (comment) It's not worked upon currently. Would love to hear some suggestions on this.. |
I'd definitely like to help if I can. Would you mind chatting a bit via email? I sent you one a few minutes ago before I stumbled upon this ticket. |
@satyan Thanks, your example helped me to understand how to implement oneToMany relationships ! I suggest you to maybe add this on your doc as it is not so clear how to implement it, I struggled a bit before I found this issue ! |
+1 on the suggestion of @OlivierRevial to add the example on the documentation! |
yes, +1 on adding that to the documentation! i was struggling with this for hours because i didnt know that Collections aren't supported |
What about one to many relationships? Are this being worked on? |
An book can have many Authors how to insert the values in this condition ?
above code is correct ? To-Many lists Relations? code from AddNoteActivity of Samples
How to save if there are list of many tags to the note?
this Will work for inserting many tags to to a single note? or any other ways to achieve this? |
Ah just ran into this solution, but wanted to share what I ended up doing, maybe it helps someone out:
Not the most efficient/clean way but works for me for now (using small lists). Hoping to see proper list support soon though! |
Thanks Cuberob for the Info, I finally did it in the same way by storing the string in json format! but json/gson parsing while retrieving inserting will effect performance! GeenDAO have mentioned some solutions for this.. Need try that Ref: #195 |
This is definitely much needed functionality. Is there a way to pass values to the constructor for sugar orm? I know it needs the default constructor. If possible then we can build up the many - many lists by passing the parent_id to the child_id class. So on querying the parent, in the constructor you do the find all by parent_id and build that object in the parent. |
This is a critical feature and it will go into 1.4.0. |
Is this feature present in 1.4 beta release ? |
I don't understand the example - I'm using 1.4, but the code won't compile.
The "author.getId()" always says "cannot resolve symbol". This example seems very incomplete - neither class extends SugarRecord, and author and getId() are not visible symbols within the Author class. Am I missing something here? Also, if I switch the anonymous String to an anonymous string array
That returns a long, not a string. Syntax errors abound. |
@MisterSpicy, please try this:
|
@rdenadai Hey, thanks for that, I was pretty tired and a little frustrated. I also found the whole set of examples in the project, which implements things like you have. Hopefully the docs get updated soon for 1.4! |
sorry,who can give me one full example about one-to-many?I'm always not success |
Documentation did not help guys. I tried more than 1 time to implement simple Relation One to Many without succes. Android crash every time saying: android.database.sqlite.SQLiteException: no such column: travelSugar (code 1): , while compiling: SELECT * FROM PLACE_SUGAR WHERE travelSugar = ? where travelSugar is like "author" in @MisterSpicy above comment |
@multivoltage In Sugar your field(travelSugar) will be represented as 'travel_sugar' in the database. So try like this YourClass.find(YourClass.class,"travel_sugar = ?", "somthing"); |
I don't understand how the example is supposed to work when you can't store objects as parameters in sugar, I mean the one with the Book and the Author. I get an error "no such column: author (code 1)" which is exactly what I expected when I saw the example, am I missing something? If I could store objects as parameters in the database I wouldn't need to use a one to many solution. EDIT: I found my problem, I had a table with something like this "nameTable", but sugarORM automatically changes those kinds of names to "name_table", so I had to search for it that way. |
@satyan So we will have a direct support for many-to-many relationship in 2.0.0 for sure? |
Hello.
This code is really needed?
Thank you for helping me. |
I never would have thought that I needed to check to see if a highly regarded ORM supported one-to-many relationships. This is absolutely crucial. Is there ever going to be an update to support this? |
public String venueId; this is my response model keys.. what should i do so that i can store that profileImages array in my database using SugarORM v1.5? |
I'm having save issue with one to many relationship. The example here http://satyan.github.io/sugar/creation.html#why is too vague and it also seems that @OneToMany annotation is removed in 1.5 release. |
If someone can help. I have a similar kind of issue.. https://stackoverflow.com/questions/45389403/sugarorm-not-saving-object-inside-arraylist |
Hi
Could you give some tips on how to create One To Many relationship?
For instance
public class Person {
private List cars;
}
I couldn't find anything on how Collections are stored, but documentation says "This would help with one-to-one and one-to-many relationships"
Thanks
The text was updated successfully, but these errors were encountered: