douguio0185 2014-12-24 15:07
浏览 15

parent_id匹配时CakePHP是unique

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能