php - 雄辩在哪里堆积
问题描述
我的问题如下图
$data = Model::whereRaw(<condition 1>)
$data1 = $data->whereRaw(<condition 2>)
$data2 = $data->whereRaw(<condition 3>)
每当我打印时,$data2->toSql()
我都会得到这个
select * from table where <condition 1> and <condition 2> and <condition 3>
代替
select * from table where <condition 1> and <condition 2>
解决方案
因为 $data, $data1,$data2 指向内存中同一个对象的指针......
解决这个问题:
$data = Model::whereRaw(<condition 1>);
$data1 =(clone $data)->whereRaw(<condition 2>)
$data2 = (clone $data)->whereRaw(<condition 3>)
推荐阅读
- ruby-on-rails - 如何将特定的 CSV 标头分配给 Rails CSV 生成器中的特定数据
- java - 如何在凯撒密码中包含“_”
- entity-framework-core - FromSql 与不存在的实体
- html - 数字输入错误地接受带小数位的浮点数
- python - 如何创建新列名并从其他列中的列表填充行值
- java - 一直在尝试使用 Java 的堆栈/回溯来解决 n-queens 问题。不是很有经验,想看看哪里出错了
- c - VS2019编译器支持哪个版本的C?
- c - C中的分段错误11在排序列表中插入节点
- css - 是什么导致 Safari 上的语义 UI 组件随机突出显示?
- javascript - 我可以在 SVG 文件中嵌入 JavaScript 代码吗?