• 0

[database] Nested Sets, product multi-categorisation


Question

I am working on a database model for an ecommerce project. Very simply put, we have products, which need categorisation - done this 1000 times before.

Except this time, we have decided to use Nested Sets as a structure for categorisation. In all honesty, I agree with this method, as it describes a parent/child/sibling heirarchy very well (IMHO).

However, here is where I am stumbling...

Each product can exist in more than one category. OK, maybe that's not true... It may be better to state that each category may have more than one parent.

Example:

One product range we sell is DJ lighting. Let's take the example of a bulb for a moonflower light.

This wants to be within the categorisation DJ Equipment / Lighting / Bulbs / {specific product}

BUT

We also want to categorise it as Accessories / Bulbs / {specific product}

I have a products table, with an "ID", etc per product.

I have a categories table with an "ID", "Name" per category.

I have a product_categorisation table with a "ProductID", "CategoryID" with a one-to-many mapping.

So this allows a product to be in many categories. So not only on our back-end we can multi-categories a product, but we can utilise this for searches and navigation.

My thought is this... A category_heirarchy table, using nested sets, with an "ID" (for internal table purpose), "lft", "rgt" and "CategoryID" (mapping to the categories table).

Am I over-complicating things? Do I need a product to fit into multiple categories, or categories to fit to multiple parents: eg. Does the category of Bulbs need to appear twice in the heirarchy - with the product under each / or does a pointer to bulbs appear twice in the heirarchy, bulbs only exist once as a category, and the product link to that category?

Hah, sorry if this is really noob!

2 answers to this question

Recommended Posts

  • 0
I have a products table, with an "ID", etc per product.

I have a categories table with an "ID", "Name" per category.

I have a product_categorisation table with a "ProductID", "CategoryID" with a one-to-many mapping.

So this allows a product to be in many categories. So not only on our back-end we can multi-categories a product, but we can utilise this for searches and navigation.

My thought is this... A category_heirarchy table, using nested sets, with an "ID" (for internal table purpose), "lft", "rgt" and "CategoryID" (mapping to the categories table).

I use a similar system, just named slightly differently. Literally:

Category > Child Category

Category > Product

Category > Child Category > Product, etc...

It's quite a common hierachy design decision, its flexible enough to be robust.

Am I over-complicating things? Do I need a product to fit into multiple categories, or categories to fit to multiple parents: eg. Does the category of Bulbs need to appear twice in the heirarchy - with the product under each / or does a pointer to bulbs appear twice in the heirarchy, bulbs only exist once as a category, and the product link to that category?

I would stick with a product in multiple categories, not categories as children of multiple categories (although, there are situations where that is useful). The problem with the latter solution is that all the products of that child category would appear in all categories where that category is a child, this is not always the case, you often want a granular set of products to match the specific category path that has been followed.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'd say the first one failed to be as popular as Apple anticipated, but the easy adjustment here is to make fewer of them next time around. It would only be a "flop" if it isn't possible for Apple to recover the design and factory tooling costs given the number of units sold, which I doubt would be the case. It isn't like no one bought them; it just failed to become the new hot phone of the year.
    • You're right that it does not follow the plain meaning of the word, but in this context, it is a legal term defined in 49 U.S.C. Kind of how "wire fraud" laws apply even if a physical wire was not used. Given that it is codified in law, and it isn't just automotive journalists that don't understand evolving technology, I highly doubt congress would change a well understood term just because technology makes the term slightly less actuate.
    • This is exactly why I keep saying we are not ready for human free self-driving. These little "bugs" are may seem like random one-offs. There was also the Waymo that drove between police with drawn weapons and the suspect they were pointing them at. From a software perspective it is easy to understand how those extremely rare situations may not have been programed for, but that is the point. If AI needs to be told to watch out for every possible contingency, then it can never be successful. There will always be the possibility of a first encounter that the AI needs to understand to avoid.
    • TeraCopy 4.0 Final by Razvan Serea TeraCopy is a compact program designed to copy and move files at the maximum possible speed, also providing you with a lot of features. Copy files faster. TeraCopy uses dynamically adjusted buffers to reduce seek times. Asynchronous copy speeds up file transfer between two physical hard drives. Pause and resume transfers. Pause copy process at any time to free up system resources and continue with a single click. Error recovery. In case of copy error, TeraCopy will try several times and in the worse case just skips the file, not terminating the entire transfer. Interactive file list. TeraCopy shows failed file transfers and lets you fix the problem and recopy only problem files. Shell integration. TeraCopy can completely replace Explorer copy and move functions, allowing you work with files as usual. TeraCopy is free for non-commercial use only. For commercial use you need to buy a license. The paid version of the program includes the following features: Copy/move to your favorite folders. Save reports as HTML and CSV files. Select files with the same extension/folder. Remove the selected files from the copy queue. Download: TeraCopy 4.0 | 14.6MB (Freeware, paid upgrade available) View: TeraCopy Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
    • First Post
      BizSAR earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      586
    2. 2
      +Edouard
      187
    3. 3
      Michael Scrip
      74
    4. 4
      PsYcHoKiLLa
      72
    5. 5
      neufuse
      69
  • Tell a friend

    Love Neowin? Tell a friend!