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
jagguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.