Eloquent where 子句返回错误条目

问题描述 投票:0回答:1

在我的 Laravel/Lumen 项目(版本 8)中,我尝试从我的 Oracle 数据库中检索数据,但我得到了意想不到的数据。

我的数据库包含以下 4 个条目:

ID 外国身份证 姓名
1 100 条目1
2 100 条目2
3 100 条目3
4 200 条目4

我的模特:

class Entry extends Model
{
    protected $connection = 'MyConnection';
    protected $table = 'MY_TABLE';
    protected $fillable = ['foreign_id', 'name'];
    protected $hidden =  ['foreign_id'];
    protected $casts = [
        'foreign_id' => 'integer'
    ];
}

当我执行下面的代码行时,只返回 ID 为 1 的 Entry1,而我期望的是一个空集合:

Entry::where([['id', '!=', 1], 'foreign_id' => 100, 'name' => 'Entry1'])->get();

分析问题,我也试着写了排队where子句:

//returns all but Entry1; correct
Entry::where(['id', '!=', 1])->get();

//returns Entry2 and Entry3; correct
Entry::where(['id', '!=', 1])->where(['foreign_id' => 100])->get(); 

//returns only Entry1; wrong, should be an empty collection
Entry::where(['id', '!=', 1])->where(['foreign_id' => 100])->where(['name' => 'Entry1'])->get(); 

生成的sql查询如下所示:

"select * from "MY_TABLE" where ("ID" != ? and "FOREIGN_ID" = ? and "NAME" = ?)"

流明版本为:8.3.4

编辑:

我已经在另一台笔记本电脑上试过了。在那里我得到一个空的集合。 您是否知道什么配置/设置可能会起作用,我的查询以两种不同的方式解释?

php laravel oracle lumen
1个回答
0
投票

尝试下面的代码

Entry::where([
['id', '!=', 1], 
['foreign_id', 100], 
['name', 'Entry1']
])->get();
© www.soinside.com 2019 - 2024. All rights reserved.