这是我的模型关系:
expenseClaim hasMany expenses
expenses HABTM expenseCodes
expenseCodes HABTM expenses
在我的 costsClaim edit() 函数中,我将所有相关的费用(每行一个)拉入一个表单中,以便用户可以编辑。
在每一行(费用)上,我都有一个下拉菜单,因此他们可以选择费用代码(与费用声明 add() 函数相同)。
但是,在编辑视图中,用户先前选择的费用代码尚未从数据库中填充...
我怎样才能将费用索赔、费用和昂贵的代码都拉到同一页面中?
我试过了:
$this->ExpenseClaim->recursive = 2;
没有成功。
费用索赔模型:
<?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' => ''
)
);
}