Note that there are some explanatory texts on larger screens.

plurals
  1. POAssociations in CakePHP with non-conventional database
    primarykey
    data
    text
    <p>We are converting an application for use with CakePHP 2.0.3. For some reason, I cannot seem to set proper relations between my models. </p> <p>Here's an example:</p> <ul> <li>User (id, petid, country, picid, ...)</li> <li>Pet (id, userid, picid, ...)</li> <li>Picture (id, albumid, ....)</li> <li>Album (id, userid, petid, ...)</li> </ul> <p>The meanings of these are the following: - A user can have multiple pets, but can only have selected one pet at the same time (therefore, petid in User)<br /><br /> - Pets belong to one user<br /><br /> - Pets and Users can have multiple pictures, but only one profile picture, therefore Pet.picid and User.picid<br /><br /> - Pets and users can have multiple Albums<br /><br /></p> <p>I set up my models in CakePHP, but I cannot figure out which relations to use between them since the Database is not following the conventions. I've tried the following:</p> <ul> <li><p>User<br /> -> hasMany(Pets)<br /> -> hasOne(Picture)<br /> -> hasMany(Album)<br /></p></li> <li><p>Pet<br /> -> belongsTo(User) (works fine, with foreignkey userid)<br /> -> hasMany(Album)<br /> -> hasOne(Picture)<br /></p></li> <li><p>Album<br /> -> hasMany(Picture)<br /></p></li> </ul> <p><em><strong></em> ---- Logic to achieve this? It either belongs to a user or pet-----</strong></p> <p>-> belongsTo(User)<br /> -> belongsTo(Pet)<br /></p> <ul> <li>Picture<br /> -> belongsTo(Album)<br /></li> </ul> <p>I'm new to CakePHP and cannot figure out the way to go here. Do you have any suggestions? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload