【问题标题】:Find where id is not in array of ids查找 id 不在 id 数组中的位置
【发布时间】:2013-01-24 18:57:05
【问题描述】:

查找值等于id数组的id的id:

$this->YourModel->find('all', array(
    'conditions' => array(
        "YourModel.id" => array(1, 2, 3, 4)
    )
));

我该如何做相反的事情,找到 id 与 id 数组不同的元素?

【问题讨论】:

    标签: cakephp cakephp-2.0


    【解决方案1】:

    这应该可行:

    $this->YourModel->find('all', array(
        'conditions' => array(
            "NOT" => array( "YourModel.id" => array(1, 2, 3, 4) )
        )
    ));
    

    http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions

    【讨论】:

    • 我使用的是 CakePHP 2.10,这会导致数据库错误:SELECT Division.division_id, Division.id FROM divisions AS Division LEFT JOIN @987654329 @ AS DivisionType ON (Division.division_type_id = DivisionType.id) 其中没有 (Division.id IN (1, 142, 143, 144, 168, 178, 18.. ..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多