这是我的模特关系:
expenseClaim hasMany expenses
expenses HABTM expenseCodes
expenseCodes HABTM expenses
在我的expeClaim edit()函数中,我在表单中提取所有相关费用(每行一个),以便用户可以编辑。
在每一行(费用)上我都有一个下拉列表,因此他们可以选择expenseCode(与expenseClaim add()函数相同)。
但是,在编辑视图中,尚未从数据库中填充用户先前选择的费用代码...
如何将expenseClaim,费用和昂贵的代码同时放入同一页面?
我试过了:
$this->ExpenseClaim->recursive = 2;
没有成功。
ExpenseClaim Model:
<?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' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Error - the user_id is missing',
),
),
'approved' => array(
'boolean' => array(
'rule' => array('boolean'),
'message' => 'Error - approved should be boolean',
),
),
'date_submitted' => array(
'datetime' => array(
'rule' => array('datetime'),
'message' => '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' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'ClaimStatus' => array(
'className' => 'ClaimStatus',
'foreignKey' => 'claim_status_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'Expense' => array(
'className' => 'Expense',
'foreignKey' => 'expense_claim_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}