Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find在无条件查询下返回NULL的问题 #529

Closed
wdkj opened this issue Apr 25, 2024 · 4 comments
Closed

find在无条件查询下返回NULL的问题 #529

wdkj opened this issue Apr 25, 2024 · 4 comments

Comments

@wdkj
Copy link

wdkj commented Apr 25, 2024

User::find();
Db::name('user')->find();

有数据,模型或者Db方式都已反复测试,生成SQL语句查看没有问题,在mysql工具中可正常查询到数据,请查证。

版本如下:

"topthink/framework": "^8.0",
"topthink/think-orm": "^3.0",

暂时改为如下方式了 😅

$rs = User::limit(1)->select();
$rs = $rs[0];
@wdkj wdkj changed the title find查不出数据的问题 find在无条件查询下返回NULL的问题 Apr 25, 2024
@big-dream
Copy link
Contributor

如果没有任何的查询条件 并且也没有调用order方法的话 ,find查询不会返回任何结果。

@wdkj
Copy link
Author

wdkj commented Apr 25, 2024

如果没有任何的查询条件 并且也没有调用order方法的话 ,find查询不会返回任何结果。
@big-dream
我其实是为了 M::field('SUM(money) as money, SUM(debt_money) as debt_money')->find() , 使用sum()方法需要查询多次。

@big-dream
Copy link
Contributor

可以增加条件->whereRaw('1=1')

@wdkj
Copy link
Author

wdkj commented Apr 25, 2024

@big-dream 学到了,但是还是希望TP能是一个优雅的框架 😀 ,其实即使不传条件,模型本身还附加了 delete_time=0 的条件,我加上 where('1=1') 确实find可以查到数据了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants