Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest using <a href="http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html" rel="nofollow">Aliases</a> in your relationships which will help get your head around the data being returned. </p> <p>For example, your <strong>User</strong> model could use <strong>SelectedPet</strong> and <strong>ProfilePicture</strong> in it's associations:</p> <p>User.php model</p> <pre><code>/** * belongsTo associations * * @var array */ public $belongsTo = array( 'SelectedPet' =&gt; array( 'className' =&gt; 'Pet', 'foreignKey' =&gt; 'petid' ), 'ProfilePicture' =&gt; array( 'className' =&gt; 'Picture', 'foreignKey' =&gt; 'picid', ) ); /** * hasMany associations * * @var array */ public $hasMany = array( 'Album' =&gt; array( 'className' =&gt; 'Album', 'foreignKey' =&gt; 'userid', 'dependent' =&gt; false ), 'Pet' =&gt; array( 'className' =&gt; 'Pet', 'foreignKey' =&gt; 'userid', 'dependent' =&gt; false ) ); </code></pre> <p>Your <strong>Pet</strong> model could use <strong>ProfilePicture</strong> as well:</p> <pre><code>/** * belongsTo associations * * @var array */ public $belongsTo = array( 'User' =&gt; array( 'className' =&gt; 'User', 'foreignKey' =&gt; 'userid' ), 'ProfilePicture' =&gt; array( 'className' =&gt; 'Picture', 'foreignKey' =&gt; 'picid' ) ); /** * hasMany associations * * @var array */ public $hasMany = array( 'Album' =&gt; array( 'className' =&gt; 'Album', 'foreignKey' =&gt; 'petid', 'dependent' =&gt; false ) ); </code></pre> <p><strong>Picture</strong> model:</p> <pre><code>/** * belongsTo associations * * @var array */ public $belongsTo = array( 'Album' =&gt; array( 'className' =&gt; 'Album', 'foreignKey' =&gt; 'albumid' ) ); </code></pre> <p>..and finally your <strong>Album</strong> model:</p> <pre><code>/** * belongsTo associations * * @var array */ public $belongsTo = array( 'User' =&gt; array( 'className' =&gt; 'User', 'foreignKey' =&gt; 'userid' ), 'Pet' =&gt; array( 'className' =&gt; 'Pet', 'foreignKey' =&gt; 'petid' ) ); /** * hasMany associations * * @var array */ public $hasMany = array( 'Picture' =&gt; array( 'className' =&gt; 'Picture', 'foreignKey' =&gt; 'albumid', 'dependent' =&gt; false ) ); </code></pre> <p>With regards to the logic of an <strong>Album</strong> belonging to a <strong>User</strong> or a <strong>Pet</strong>, you could just handle this in your controller when saving data or returning it. I.e User is given preference over Pet.</p> <p>I hope this helps.</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.
    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