我的数据库我有一个折扣表,用户为特定的“范围”、“类别”、“供应商”和产品类型打折。我如何让 cakephp 不允许多个“折扣”?
例如折扣是
user_id 100
category_id 1
range_id 2
producttype "doors"
discount 10%
如何确保不能为该供应商、范围、类别和产品类型创建另一个折扣?
我的折扣模型中只有一个关系(不确定这是否会有所不同)
<?php
App::uses('AppModel', 'Model');
/**
* Discount Model
*
* @property User $User
*/
class Discount extends AppModel {
/**
* Validation rules
*
* @var array
*/
//public $displayField = 'discount';
public $validate = array(
/*'title' => array(
'notempty' => array(
'rule' => array('notempty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),*/
'user_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'discount' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//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' => ''
)
);
}