I have tables like these:

human_resources:
id     name          position_id
------------------------------------
1      Jacko           3
2      Madonna     5

positions:
id    label                                upper_position_id
------------------------------------------------------------
1     President                        0
2     Director of Business       1
3     Director of Finance         1
4     Marketing Manager        2
5     Sales                              4

*positions.upper_position_id refer to positions.id

My questions:
1. What is the type of relationship between human_resources and positions?

human_resource belongs to positions, and position has many human
resources.

The naming of relationships is mostly intuitive. It is easier to look
at the 'position' first : clearly, for every position, there is an
unknown number of human resources. In other words, a position has many
human resources. The converse of "has many" is "belongs to", thus a
human_resource belongs to a position. In Cake :

class HumanResource extends AppModel
{
 var $name = 'HumanResource';
 var $belongsTo = 'Position';
}

class Position extends AppModel
{
 var $name = 'Position';
 var $hasMany = 'HumanResource';
}


2. How to get all the upper positions when i do find a human_resource?
e.g. HumanResource->find(1) so it will find the position of "Jacko"
and also upper positions of Jacko's.

I don't think there is a way to do this directly in Cake - however you
might have noticed a recent thread (entitled "Reverse recursive
findAllThreaded queries?") where the same problem was highlighted, and
several possible solutions were given :
http://groups-beta.google.com/group/cake-php/browse_thread/thread/6c7cdd0cc5160a19

Anselm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to