- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用关系从模型中检索一些结果,并且正在尝试对该关系应用一些过滤器。
这是模型:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserProduct extends Model
{
protected $primaryKey = null;
public $incrementing = false;
protected $table = "user_product";
public $fillable = [
...
"product_id",
"user_id",
"is_featured",
"is_hidden_from_latest"
...
];
public function product()
{
return $this->belongsTo("\\App\\Models\\Product", "product_id", "id");
}
...
}
这是相关模型:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = "products";
public $timestamps = false;
public $fillable = [
...
];
public function userProduct()
{
return $this->hasOne("\\App\\Models\\UserProduct", "product_id", "id");
}
...
}
下面是对UserProduct
模型和产品关系的查询:
$user_products = UserProduct::with("product")
->whereHas("product", function($q) {
$q->where("product_status", "live")
->where("parent_child", "Child");
})->where("is_featured", 1)
->orWhere("is_hidden_from_latest", 0)
->orderBy("is_featured", "desc")
->orderBy("updated_at")
->get();
问题是 whereHas
子查询似乎没有过滤任何东西,无论我为每个 product_status
和 parent_child
使用什么值进行比较>.
我有没有做错什么?
更新:似乎游戏破坏者是最后的这两个 where()
语句:
....
->where("is_featured", 1)
->orWhere("is_hidden_from_latest", 0)
....
更具体地说是 orWhere()
语句。
最佳答案
试试这个
$user_products = UserProduct::with("product")
->whereHas("product", function($q) {
$q->where("product_status", "live")
->where("parent_child", "Child");
})
->where(function ($query) {
$query->where("is_featured", 1)
->orWhere("is_hidden_from_latest", 0);
})
->orderBy("is_featured")
->orderBy("updated_at")
->get();
关于php - 拉维尔 5 : Eloquent whereHas subquery doesn't filter results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42719664/
我们需要选择只使用连接到机器的标签的测试。 标签对测试来说是多对多的。 (TagTest关联表) 标签对机器来说是多对多的。 (TagMachine关联表) 例子: 如果测试有标签 [A,B,C] 而
我有这种删除查询: DELETE FROM SLAVE_TABLE WHERE ITEM_ID NOT IN (SELECT ITEM_ID FROM MASTER_TABLE) 有没有办法优化这个?
我试图通过加入子查询来获得 groupBy 计数的平均值。不知道这是否是正确的方法,但除了 mysema 文档之外,我对子查询一无所知。 设想: 客户平均每个产品做了多少订单? 含义:客户订购产品。因
我的问题中有两个表,一个是 USER 表,其中包含用户的所有详细信息,另一个是 REQUEST 表,其中包含所有用户向所有用户发出的好友请求。我想列出登录我的应用程序的一位用户的所有 friend 。
我有一个 Oracle SQL 查询,它在其列输出中包含计算。在这个简化的示例中,我们正在寻找日期在某个范围内的记录,其中某些字段与特定事物相匹配;然后对于这些记录,取 ID(不是唯一的)并再次搜索表
https://sqlzoo.net/wiki/SELECT_within_SELECT_Tutorial 的问题 7 “找到每个大陆中最大的国家(按面积),显示大陆、名称和面积:” 我不明白为什么
这是我面临的问题的最低工作版本。正在关注the JSON table example在文档页面上,我在 MySQL 8 中有下表 test,其中 id 是一个 INT 字段,data 是一个 JSON
这是我面临的问题的最低工作版本。正在关注the JSON table example在文档页面上,我在 MySQL 8 中有下表 test,其中 id 是一个 INT 字段,data 是一个 JSON
我在 u-sql 中使用以下查询时遇到编译错误: @CourseDataExcludingUpdatedCourse = SELECT * FROM @CourseData AS cd WHERE c
我试图在 querydsl 中表示以下查询: select a1.agreement_id, ad1.agreement_detail_id from agreement a1 inner joi
我必须根据 where 子句对某些列进行求和,以便更好地理解我在这里实现临时表 declare @tbl table(a int ,b int,c int) insert into @tbl valu
我正在使用 Hive 0.9.0 并且我正在尝试执行查询,即 `SELECT a.id, b.user FROM (SELECT...FROM a_table) a, (SELECT...FROM b
假设我们有以下 Student.mdd: person=not null ptr general.Person interests=set general.ActivityField educatio
我对 HQL 查询有一些问题。我会像这样使用带有别名的子查询 select distinct a.some1, count(a.some2), (Select count
我遇到了一个问题,Sequelize 创建主模型的子查询,然后将包含与该子查询连接起来,而不是直接与主模型表连接。包含的查询条件最终位于子查询的 WHERE 子句中,这使其无效。我已经缩短了名称,希望
顾问给我发送了这个代码示例,这是他希望得到的东西 SELECT m1~vbeln_im m1~vbelp_im m1~mblnr smbln INTO CORRESPONDING F
我需要提取存档表中没有历史记录的记录。 2 需要在存档中检查 1 条记录的字段。 从技术意义上讲,我的要求是左侧连接,其中右侧为“空”(也称为排除连接),在 abap openSQL 中通常是这样实现
我在 sqlite 中面临以下难题,想知道我是否缺少关于 sqlite 方言的某些内容。 基本上,当我在一张表中要求总唯一值时,我会得到一个数字。当我要求第二个表中存在的这些值的子集时,我得到的数字较
以下结果是根据我创建的 SELECT 语句创建的: total date currency provider conversion_to_usd 170.
我想检查 cust_data_card_id 是否存在于表 tbl_cust_data 中,是否存在于表 tbl_cust_dump_data.cust_data_card_id 等中 我写了下面的代
我是一名优秀的程序员,十分优秀!