android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.47k stars 8.29k forks source link

How to handle Complex Entity with List of Custom Object in Room ? #58

Closed anil-gudigar closed 7 years ago

anil-gudigar commented 7 years ago

I have used room for https://newsapi.org , i have problem in saving Articles which consists of List of Articles and Top Response Object has Source Detail. { "status": "ok", "source": "the-next-web", "sortBy": "latest", -"articles": [ -{ "author": "TNW Deals", "title": "Build for the web of the future with the Perfect Python Programming Bundle — for under $25", "description": "If you’d like to elbow your way into the ranks of professional web development, you may want to seriously consider mastering Python as one of your go-to coding tools. It’s easy ...", "url": "https://thenextweb.com/offers/2017/06/11/build-web-future-perfect-python-programming-bundle-25/", "urlToImage": "https://cdn3.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/vkUK1Nd.jpg", "publishedAt": "2017-06-11T17:33:12Z" }, -{ "author": "Alice Bonasio", "title": "Can SnoreTech Save my Marriage?", "description": "I don’t know what Donald Trump’s excuse is, but whenever I find myself tweeting something incoherent at around 3 in the mornings it’s usually because my husband’s snoring has ...", "url": "https://thenextweb.com/contributors/2017/06/11/can-snoretech-save-marriage/", "urlToImage": "https://cdn2.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/527px-PSM_V11_D725_Head_brace_to_eliminate_snoring.jpg", "publishedAt": "2017-06-11T15:16:58Z" }] } want persists Articles Response and Articles in 2 Tables i.e @embedded but its a problem and also periodically update the new News feed into Article Table. As of now in my Github Repo i have used type converter to save articles as json and retrieve . https://github.com/anil-gudigar/Twill

let me know how to do it?

yigit commented 7 years ago

It is usually a good practice to separate your data transfer objects from your entities. So when you pull the data, you have to normalize it into your entities. When pulling the data, you can use the @Relation annotation.