I have a Products Table as NodeID | ParentNodeID | NodeName where “node” can be a “Product” or a “Category”. Say for example:
NodeID | ParentNodeID | NodeName
0|| ||Root
1|| 0 || Electronics
2 || 1 || Mobiles
3 || 2 || Samsung
4 || 2 || Apple
5 || 2 ||Nokia
6 || 5 || Nokia 1100
7 || 5 || Nokia Lumia 800
and so on..
Now, Root > Electronics > Nokia are the Categories and Nokia 1100 is the Product.
For each of the product, I want a particular set of Attributes(Specifications) related to the product.
I am maintaining that relation in a table ProductAttributes with columns : AttributeId || AttributeName || Value || NodeID where i will be keeping all the Attributes and their corresponding values for a particular NodeID (E.g. Nokia 1100).
So when the user is posting “Nokia 1100”, he will have all the Attributes with pre-filled values in the UI.
Suppose now what the user is posting, is not there in the database, Eg. say he is posting “Samsung Focus”. He will now have an option to select the “category” under which he will be posting this request, “Mobiles” in this case.
So what i want is somehow, the user should be shown Attributes related to Mobiles only (with/without default values) which the user can then select whichever is applicable and then post the request.
For this, i am thinking of putting some default Attributes to the “Categories”, which will be available whenever he selects that category.
But i am unable to come up with a proper table structure for this approach and the relations. I mean, there might be multiple attributes for a single category and there may be multiple values for each of the attribute.
I hope i am able to portray what i am trying to do here,
any help is appreciated.
It sounds like you are looking for an EAV (Entity Attribute Value) pattern
http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model
Be aware though that this approach (some say anti-pattern) is strewn with pitfalls.