[英]How do I query on my has_many association's table's parameter?
Category
String id;
String name;
boolean enabled;
Product
String id;
String name;
boolean enabled;
int categoryId;
I need to search for all of the enabled
categories that actually have products
and those products
should have enabled
set to true
. 我需要搜索实际拥有products
所有已enabled
类别,并且这些products
应该已enabled
设置为true
。
I am not really that adept at SQL queries so could someone please point me to the right direction? 我不是那么擅长SQL查询所以有人可以指出我正确的方向吗?
Here it is: 这里是:
SELECT Category.* FROM Category
INNER JOIN Product ON Category.id=Product.categoryId
WHERE Category.enabled = 1 AND Product.enabled=1
GROUP BY Category.id
I am not sure about the boolean values representation in your DB, assuming it is 1/0 我不确定DB中的布尔值表示,假设它是1/0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.