I am new to core data. I am banging my head on the wall trying to understand how should I design the data model for this application.
I have to create a database for books.
Books have the following characteristics:
.englishName
.italianName
.frenchName
.spanishName
.number
Books can be of two kind: free or non-free.
Books can be sold individually or in bundles.
A bundle can represent a bunch of books.
A book can be in one or more bundles.
What I need:
- The ability to mark as paid a
bundle or/and book. - the ability to retrieve all non-free or all free
books, all books from a bundle, all
books that were bought.
How I imagine this could be done: I would create 3 entities: Bundle, Product and Type and make all products bundles, I mean, a bundle with 1 product or with multiple products.
Bundle
.Number
.Paid
-relation to product (fromBundle) to-many
Product
.nameEN
.nameIT
.nameFR
.nameSP
.Number
-fromBundle (relation to Bundle) to-many
-fromType (relation to Type)
Type
.kind
-relation to Product... to-many
But I am not sure this is not the way, simply because there’s no way to define a bundle name in all 4 languages and if I add those attributes to the bundle, I will end with a lot of redundancy…
please help meeeeeee! thanks.
You may be overcomplicating this by introducing Product and Type – all you should really need are the Book and Bundle entities, with a many-to-many relationship between them. Then, to deal with the use cases you presented:
freeattribute set to the appropriate value (or thepricevalue zero or nonzero, depending on how you’re storing this attribute)[bundle books]– the many-to-many relationship gives you this directlypaidThis way, you can keep your four name attributes on the Book itself and not worry about them (unless you have to name Bundles, but those should be distinct names anyway). Furthermore, it’s conceptually simple – you don’t have to worry about what precisely constitutes a Product or semantics of that manner.