[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

cakephp association confusion

Hi,

I have a simple question on associations in cakephp.
I have a user , role and tutor table.
The  issue is how do i define this where I have a admin user who can view tutors but there is no tutor entry with this user? Or do I need to bother  as not all users are tutors anyway.

I can create a user that is a tutor and have the userID in the tutor table as a foreign key.
The role is the user type like admin, tutor etc which is linked to the user.



 public $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id'
        )
    );

 public $hasOne = array(
        'Tutor' => array(
            'className' => 'Tutor',
            'dependent' => true
        )......



http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
0
jagguy
Asked:
jagguy
1 Solution
 
Scott MadeiraCommented:
It's been a while since I've used CakePHP but wouldn't you want to handle the admin case in your controller or business object?  If the user is an admin then they could access a method that pulls all tutors or all admins or all users.  If the user is not an admin then they could see only the tutors or whatever subset of the data you want them to see based on your business rules.

If the functions of an admin user and a non-admin user are really different then you may want to consider having two different models defined and then load the appropriate model in your controller based on the role of the user.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now