[英]CodeIgniter DataMapper include_related only including one related model
I have a Product_faq class which has a $has_many
relationship to a Product class. 我有一个Product_faq类,它与Product类具有
$has_many
关系。 I have a Product class which has a $has_many
relationship to the Product_faq class. 我有一个Product类,它与Product_faq类具有
$has_many
关系。 These two classes are joined using a product_faqs_products
table. 使用
product_faqs_products
表将这两个类连接product_faqs_products
。
I am trying to use the following code to retrieve a specific Product_faq along with the Products associated to it: 我正在尝试使用以下代码来检索特定的Product_faq及其关联的产品:
$faqs = new Product_faq();
faqs->include_related('product', null, true, true)->get_by_id(25);
foreach($faqs->product as $product){
echo $product->id.PHP_EOL;
}
There are three products related to this product_faq, but this code is only outputting the first one. 有3个与此product_faq相关的产品,但是此代码仅输出第一个产品。 Is this the intended functionality?
这是预期的功能吗? Is there any way for me to include all of the related products on this query?
我有什么办法可以在此查询中包括所有相关产品?
get_by_id
function returns one row because of getting product_faqs_products
. 由于获取
product_faqs_products
get_by_id
函数返回一行。 id
that primary key is 25. 主键为25的
id
。
Try where
clause with foreign_key
following: 请尝试使用
foreign_key
where
子句,如下所示:
$faqs->include_related('product', null, true, true)->where('product_id', 25);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.