繁体   English   中英

如果使用列,如何获取联接数据?

[英]How to get join data if using columns?

我有两个表,ProductGroup和ProductGroupTranslation结合在一起。

在ProductGroup中,我有ID;在翻译表中,我有标题。

现在,我想获取所有产品组:

$categories = ProductGroup::find(array(
    "product_group_id IS NULL",
    "order" => "id DESC"
) );

这有效,我可以通过$categories->productgrouptranslation->getTitle();访问翻译$categories->productgrouptranslation->getTitle();

但是,如果我只取出列,如何访问联接表:

$categories = ProductGroup::find(array(
   "columns" => "id",
    "product_group_id IS NULL",
    "order" => "id DESC"
) );

这是您使用的技术的限制。 如果您指定要从中检索数据的列,那么这些是您将只能访问的列。

如果你问“哪些列,我需要指定只获取ID和标题了加入结果集”,然后我怀疑答案是列的一个阵列通入columns与前面加上表名的列名:

$categories = ProductGroup::find(array(
   "columns" => "ProductGroup.id,ProductGroupTranslation.title",
   "product_group_id IS NULL",
   "order" => "id DESC"
) );

将上面的表名替换为实际的表名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM