Solved

CakePHP: Modelling Employee Hierarchy

Posted on 2009-04-07
1
1,499 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now