0
votes

I have 5 tables in my database. These are users, staffs, customers, managers, manager_members.

The users table only contains the account information: id, username, password, last_login, status.

The manager_members contains the id and position of a manager.

The staffs and customers tables contain the general information of user: name, age, gender, etc. These 2 tables also contain another column name user_id.

The managers table contain general information of the manager: name, age, gender, etc. It also contains 2 columns user_id and manager_member_id.

My question is I am doing the right job of creating the database with the foreign keys?

I just bake my models whenever I create a table.

So far what I see are:

  1. Users hasMany Manager, Staff, Customers
  2. Manager belongsTo User, Manager belongsTo ManagerMember
  3. Staff belongsTo User
  4. Customer belongsTo User
  5. ManagerMember hasMany Manager

Not sure if number 5 is correct.

1

1 Answers

0
votes

I would make a few small tweaks to your setup just to match with the CakePHP conventions.

The db tables you'll want.

users, 
staff,  
customers,  
managers,  
managers_users

In CakePHP, the foreignKey convention is singular suffixed with _id.

  • Users hasMany Manager then you'd want Managers.user_id.
  • Users hasMany Staff then you'd want Staff.user_id.
  • Users hasMany Customers then Customers.user_id
  • Manager belongsTo User then, no change.

You can read more about relationships on the book.