?
Solved

CakePHP: Modelling Employee Hierarchy

Posted on 2009-04-07
1
Medium Priority
?
1,513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
asianandrew earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 count occurrences of each item in an array.
Suggested Courses

801 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