im my database i have a discounts table, a user makes a discount for a specific "range","category","supplier" and product type. How do i make cakephp not allow multiple "discounts"?
eg a discount is
user_id 100
category_id 1
range_id 2
producttype "doors"
discount 10%
How to i ensure that another discount cant be created for that supplier,range,category and product type?
My Discount model has only one relation ship in it (not sure if that makes a difference)
<?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' => ''
)
);
}