2012-07-05 4 views
1

내 데이터베이스 나는 "할인"테이블을 가지고 있는데, 사용자는 특정 "범위", "카테고리", "공급자"및 제품 유형에 대해 할인을합니다. 어떻게하면 cakephp가 여러 "할인"을 허용하지 않게 할 수 있습니까?cakephp 2.0 고유 한 다중 필드 유효성 확인

할인은 예를 들어

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' => '' 
     ) 
    ); 


} 
+1

을 거의 http://stackoverflow.com/questions/11173835/cakephp-2-1-custom-validation-rule-check-for-unique-field-valu과 동일 전자 조판/11175385 # comment14663880_11175385 - 가능한 해결책에 대한 답변보기 – mark

+1

중복 된 http://stackoverflow.com/questions/2461267/cakephp-isunique-for-2-fields/2464201#2464201 (내 대답 참조) – RichardAtHome

+0

빠른 재생과 답변을 주셔서 감사합니다. –

답변

0

그것은을 위해, 여러 필드 모델에서

을 갖는 cakephp 독특한 처리하는 것은 매우 간단합니다 (그 차이를 만드는 경우 확실하지) 거기에 하나의 관계 배를 가지고 할인 유효성 검사 규칙 좋아 :

public $validate = array(
     'discount' => array(
      'numeric' => array(
       'rule' => array('numeric'), 

      ), 
      'isUnique' => array(
       'rule' => array('isUnique',array('user_id','category_id','range_id','producttype'),false), 
       'message' => 'discount already Exist.' 
      ) 
     ), 
    );