Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The quick answer is that your associations are wrong. The long one follows:</p> <p>First of all there is no association called <code>hasAndBelongsTo</code>. The association name is <code>hasAndBelongsToMany</code>. Furthermore the associations you've put together in the <code>Message Model</code> are a totally wrong or if I may put it this way - you may have not understood them correctly. So the quick fix would be to remove the <code>hasMany</code> to <code>MessageUser</code>, the <code>belongsTo</code> <code>User</code> and the wrong <code>hasAndBelongsTo</code> <code>Message</code> and add a <code>hasAndBelongsToMany</code> association to User.</p> <p>If you want to have <code>Message hasAndBelongsToMany User</code> just use that. How <a href="http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm" rel="nofollow noreferrer">is described here</a>. Also HABTM has be discussed many times here so I'm not going to go into detail about it.</p> <p>However I would like to point you to another possible set up. Now I am proposing this because I saw you tried to also use <code>hasMany</code> so there is the possibility to use the so-called <code>hasManyThrough the Join Model</code>, but usually that is to be used when you want to store additional data in the join model (MessageUser in your case). Check <a href="https://stackoverflow.com/questions/12224596/self-habtm-or-hasmany-through-concept-confusion">this question out</a>. </p>
    singulars
    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.
 

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