kee2ka4 Posted April 16, 2010 Share Posted April 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/198736-cakephp-framework-model-association-help/ Share on other sites More sharing options...
244863 Posted April 20, 2010 Share Posted April 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198736-cakephp-framework-model-association-help/#findComment-1045149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.