Jump to content

cakePHP Framework - model association help


kee2ka4

Recommended Posts

Hey Guys,

 

I am a newbie in cakephp and wanted some guidance in the model associations before I bake the application. I have identified three entities called Users, Assessors and Invoices but couldn't figure out the correct associations since their logic is a lill different. Here is a brief summary of the web app:

 

1. Users login to the system and can search for Assessors. Users can select an Assessor and can only select one Assessor. If they want to select another Assessor then they need to first remove their current Assessor. Once the user selects an Assessor, their selected Assessor can create an Invoice that the user can view. Users can have multiple Invoices created by their selected Assessor.

 

2. Assessor’s can login to the system and view list of users that have selected them. They can create Invoices for their users. So Assessor can create zero or many invoices for their users.

 

I have done some research on model associations and was thinking of using the one to one relationship where dependence is equal to "False" on Users and Assessors so:

 

User has one Assessor but that would make the belongsTo association as a natural complement to the hasOne, so Assessor belongsTo Users - this is not necessarily true since an Assessor many not have any users or a User may not have any Assessor. Can someone provide me with some light here, I am confused :-)

 

I think I am clear with the association of Invoices with Users and Assessors, which is

 

Users has many Invoices

Assessors has many Invoices

Invoices belong to Users

Invoices belong to Assessors

 

Correct me if I am wrong but I am not very clear on what association to use between Users and Assessors?

 

Thanks,

Ket

 

Link to comment
Share on other sites

I think the thing to bear in mind here is that you have two options:

hasOne

hasMany

Both of which allow you to have 0 associations, it just means that $data will be empty.

So the only question is will users have many or one assessor? and vice versa.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.