Solved

CakePHP: Modelling Employee Hierarchy

Posted on 2009-04-07
1
1,500 Views
Last Modified: 2013-11-10
Hi All,

How do I model a company's hierarchy? Each employee has zero or more managers and at the same time, might have zero or more employees reporting up to him/her.

Example: CEO --> Directors --> Managers--> Individual Contributors

Is this a HABTM relationship with one table ie. an employee belonging to many employees/having many employees?

Any help or direction would be aprpeciated.

Thanks.
0
Comment
Question by:swfoo
1 Comment
 
LVL 3

Accepted Solution

by:
asianandrew earned 500 total points
ID: 24094292
You can use a HABTM, but I've always had difficulty with recursion - ex: find all managers who belong to CEO.

If each employee only reports to 1 person (1 employee does not report to more than 1 manager), I'd recommend using a Modified Preorder Tree Transversal (MPTT) schema which would only require 1 table.

MPTT is a little difficult to grasp at first, but can be very powerful. For instance, I could easily find all employees who work for the CEO (Directors, Managers, Individuals), or I could find their first child (Directors) with ease.

Check out the following links:
http://bakery.cakephp.org/articles/view/modified-preorder-tree-traversal-component
http://www.sitepoint.com/article/hierarchical-data-database/

Hope this helps
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question