Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP - Pulling associated model details into edit screen
    primarykey
    data
    text
    <p>This is my model relationships:</p> <pre><code>expenseClaim hasMany expenses expenses HABTM expenseCodes expenseCodes HABTM expenses </code></pre> <p>In my expensesClaim edit() function I pull in all associated expenses (one on each row) within a form so the user can edit. </p> <p>On each row (expense) I have a drop down so they can select the expenseCode (same as the expensesClaim add() function). </p> <p>However on the edit view the expenses code previously selected by the user has not been populated from the database...</p> <p>How can I pull in both the expenseClaim, expenses and expensive code into the same page ?</p> <p>I've tried:</p> <pre><code>$this-&gt;ExpenseClaim-&gt;recursive = 2; </code></pre> <p>With no success.</p> <p>ExpenseClaim Model:</p> <pre><code> &lt;?php App::uses('AppModel', 'Model'); /** * ExpenseClaim Model * * @property User $User * @property ClaimStatus $ClaimStatus * @property Expense $Expense */ class ExpenseClaim extends AppModel { /** * Display field * * @var string */ public $displayField = 'id'; /** * Model validation * */ public $validate = array( 'user_id' =&gt; array( 'notempty' =&gt; array( 'rule' =&gt; array('notempty'), 'message' =&gt; 'Error - the user_id is missing', ), ), 'approved' =&gt; array( 'boolean' =&gt; array( 'rule' =&gt; array('boolean'), 'message' =&gt; 'Error - approved should be boolean', ), ), 'date_submitted' =&gt; array( 'datetime' =&gt; array( 'rule' =&gt; array('datetime'), 'message' =&gt; 'Error - date submitted cannot be blank', ), ), ); //The Associations below have been created with all possible keys, those that are not needed can be removed /** * belongsTo associations * * @var array */ public $belongsTo = array( 'User' =&gt; array( 'className' =&gt; 'User', 'foreignKey' =&gt; 'user_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ), 'ClaimStatus' =&gt; array( 'className' =&gt; 'ClaimStatus', 'foreignKey' =&gt; 'claim_status_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); /** * hasMany associations * * @var array */ public $hasMany = array( 'Expense' =&gt; array( 'className' =&gt; 'Expense', 'foreignKey' =&gt; 'expense_claim_id', 'dependent' =&gt; false, 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '', 'limit' =&gt; '', 'offset' =&gt; '', 'exclusive' =&gt; '', 'finderQuery' =&gt; '', 'counterQuery' =&gt; '' ) ); } </code></pre>
    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