1

I have a table that is hierarchical and i want to say isUnique when the parent_id is the same. I want the below table entries to be possible:

ID, Name,    Description, Parent_id
1 , VLAN1,   TEST       , NULL
2 , VLAN2,   TEST2      , NULL
3 , VLAN100, TEST100    , 1
4 , VLAN20,  TEST20     , 1
5 , VLAN100, TEST100    , 2
6 , VLAN20,  TEST20     , 2

Below is the validation rule:

public $validate = array(
    'Vlan' => array(
            'notEmpty' => array(
        'rule' => array('notEmpty'),
        'required' => true,
            ),
            'uniqueVLAN' => array(
                'rule' => 'isUnique',
                'message' => 'VLAN already exists'
            )
        ),
        'Name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
        'required' => true,
            ),
            'uniqueName' => array(
                'rule' => 'isUnique',
                'message' => 'Vlan name already exists'
            )
    ),
);

Currently the standard isUnique from what I can see will just check all records don't match, is there a way i can say isUnique where Parent_id = Parent_id?

I cant figure out if I can do this.

Thanks in advance

Steven Marks
  • 704
  • 1
  • 6
  • 21
  • Show us your actual code. – vaso123 Dec 24 '14 at 15:10
  • You have to write your own validation rule as a function (see CakePHP book -> it's pretty easy) or check the value by returning in the controller against a new find('first',...) query. -> if empty, then isUnique, if !empty, then is NOT unique... – FishWave Nov 03 '15 at 20:32

0 Answers0