Solved

CakePHP: Modelling Employee Hierarchy

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

17 Experts available now in Live!

Get 1:1 Help Now