Reputation: 913
Scenario: I am developing an E-Commerce app on android studio. App is consuming web services to get the data. I'm designing light weight classes (just like the DB on my server) to store data that receives from server in JSON format.
Problem: I need to design relationship[Many to Many] between Cart and Product.
In DB case I were able to do it by joining tow tables in single one named CartProduct
on the basis of their primary keys.
Assumption: Since App will get data from server in JSON format, most probably there will no id
related to any entity. So I declared classes without ID.
As
Category{
String name;
List<Product> products;
}
Products{
String name;
.....
}
So how do I map these CartProducts
and OrderProducts
tables into classes. Since we have no IDs.
Upvotes: 1
Views: 235
Reputation: 748
I agree with Amit: if your JSON does not contain any attribute for the entity's identity, you cannot relate to any identy.
Are the name attributes unique? If so, they could also be used to identify entities. It is still better pratice to make a difference between name and identity. Sometimes there is "Peter"... and then there is another "Peter". Make the difference also in chosing attribute/variable identifiers, if it is an ID, do not call it "name"!
Upvotes: 1
Reputation: 11
If i understand correct, you stuck to map json with db tables, I think, you have to add some unique column, key would be preferred, otherwise you would be able to get whole data, but in case, to request any action on a single row you can stuck, there would be no identity to identify your row.
Upvotes: 1