Magento 1.7收集和连接字段
我有一个自定义表Magento 1.7收集和连接字段,magento,magento-1.7,Magento,Magento 1.7,我有一个自定义表starmall\u config\u shop,其中包含id和name 我在product表中添加了自定义属性shop\u id 我想从starmall\u config\u shop 当我这样做的时候 $rs = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('shop_id'); $rs->
starmall\u config\u shop
,其中包含id
和name
我在product表中添加了自定义属性shop\u id
我想从starmall\u config\u shop
当我这样做的时候
$rs = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('shop_id');
$rs->joinField('shop_name','starmall_config/shop','name','id=shop_id'
,NULL,'left');
我得到了错误
“on子句”中“车间id.value”处的“代码>未知列”
$rs->printlogquery(true)
给出:
SELECT `e`.*, `at_shop_name`.`name` AS `shop_name` FROM `catalog_product_entity` AS `e`
LEFT JOIN `starmall_config_shop` AS `at_shop_name` ON (at_shop_name.`id`=at_shop_id.value)
我发现我可能缺少到attributes表的连接
at\u shop\u id.value
从何而来?
如何获取查询中的名称
列
===================
当前的工作解决方案是使用:
->addAttributeToSelect('shop_id','left')
-->有效
->addAttributeToSelect('shop_id')
-->不起作用问题是
'id=shop_id'.
尝试使用
"entity_id=shop_id"
如果是shop\u id,则它是system.log中位于\u shop\u name的表中的一个字段。,我看到: 可恢复错误:无法将类别Mage\u Catalog\u Model\u Resource\u Product\u集合的对象转换为字符串 我搜索发现还有第二个参数:
addAttributeToSelect($attribute, $joinType=false)
当我现在使用:
addAttributeToSelect('shop_id', 'left');
生成的查询是:
SELECT e.*, at_shop_id.value AS shop_id, at_shop_name.name AS shop_name
FROM catalog_product_entity AS e
LEFT JOIN catalog_product_entity_int
AS at_shop_id
ON (at_shop_id.entity_id = e.entity_id)
AND (at_shop_id.attribute_id = 973)
AND (at_shop_id.store_id = 0)
LEFT JOIN starmall_config_shop
AS at_shop_name
ON (at_shop_name.id=at_shop_id.value)
但我还是不知道为什么 乍一看,您的代码对我来说似乎没问题,您正在尝试加入shop_id属性,但它不在sql中。如果有任何问题,我猜您启用了平面目录,并且需要重新索引,或者您的缓存被清除。只是选中了,但在配置中平面目录没有启用。为了开发,我禁用了缓存。确保已删除缓存文件夹,但查询仍然失败。是的,它不在sql中,我想我需要找出如何将自定义产品属性
shop\u id
放入查询中。这可能是个愚蠢的问题,但您确定删除了正确的缓存目录吗。在使用Magento时,我的第一个问题是我忘记了将var目录设置为可写目录,它在/tmp/中创建了缓存。要检查,我删除了完整的/var文件夹。它是用其中的子文件夹和文件自动重新创建的。我认为id=shop\u id
中的左侧是正确的,因为生成的连接是left join starmall\u config\u shop AS at shop\u name ON(at shop\u name.id=at shop\u id.value)
其中at shop\u name.id
是starmall\u config\u shop
表中的PK。