So, I've just started working on an iOS inventory app, which I'd like to be pretty flexible. What I want is for the user to be able to define a product category, and then its degrees of freedom, i.e. color, size, image, style, etc. I know I could accomplish this by designing a data model which includes these attributes already, but the user may not always need each one and (more troubling) may need other attributes which I hadn't thought of (like material, or brand). Is there some way to build this kind of flexible data model using CoreData? I'm sure I could do it using plists, but I want to take advantage of iCloud and NSFetchedResultsController, not to mention predicates and so forth.
Is this not even something that can be realized using a database? Now that I'm looking at the problem, it seems that maybe I'll be too limited by the enforced structure... What if a user changes the attributes after having already added records? Will I have to handle migrating the store? Ugh.
...
Ok, here's another approach, maybe somebody can comment on if this is crazy or not. I got to thinking, all of the properties a user might add are basically of the same type -- they have a string tag (the name of the property, e.g. 'color') and a series of string values (e.g. 'red', 'charcoal', 'blue', etc). So why not make these relationships, instead of attributes, of the entity? So, now I've got three entities in my object model: MerchCategory
, which is the type of merchandise we're talking about, MerchItem
, which is an individual item in the inventory, and Dimension
which is a quality that an item may have.
MerchItem
has a sku
attribute, and a many-to-many relationship to Dimension
, as well as a many-to-one relationship to MerchCategory
.
Dimension
has name
and value
attributes, and categories
and items
many-to-many relationships.
Is this a plausible schema? It seems to me that I'll be able to query for each dimension by looking at their names, and get counts of each configuration by looking at their values... And the user will be able to add new ones without mucking about with NSEntityDescription. Thoughts?