Mysql 马根托左

Mysql 马根托左,mysql,magento,zend-framework,left-join,Mysql,Magento,Zend Framework,Left Join,我正在尝试将自定义表联接到客户集合。 自定义表是: +---------+--------------------+ | user_id | linked_customer_id | +---------+--------------------+ | 4 | 12 | +---------+--------------------+ 我想将用户id添加到customer\u id与链接的\u customer\u id匹配的每个项目中 我现在有以下

我正在尝试将自定义表联接到客户集合。 自定义表是:

+---------+--------------------+
| user_id | linked_customer_id |
+---------+--------------------+
|       4 |                 12 |
+---------+--------------------+
我想将用户id添加到customer\u id与链接的\u customer\u id匹配的每个项目中

我现在有以下信息,但我收到了:

未找到列:1054未知列“main\u table.entity\u id”

    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('entity_id')
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('brand')
        ->addAttributeToSelect('group_id')
        ->joinAttribute('shipping_company', 'customer_address/company', 'default_shipping', null, 'left')
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('shipping_country_id', 'customer_address/country_id', 'default_shipping', null, 'left')
        ->joinAttribute('billing_vat_id', 'customer_address/vat_id', 'default_billing', null, 'left');

    $collection->getSelect()->joinLeft(
        array('salesrep' => 'custom_column' ), 'main_table.entity_id=salesrep.user_id',
        array('user_id' => 'salesrep.linked_customer_id')
    );

    $this->setCollection($collection);

我可能错了,但我认为因为
customer/customer
是一个EAV模型而不是一个平面模型,所以它使用的表别名是
e
而不是
main\u table

$collection->getSelect()->joinLeft(
    array('salesrep' => 'custom_column'),
    'e.entity_id = salesrep.user_id',
    array('user_id' => 'salesrep.linked_customer_id')
);
您将能够通过调试select语句来找到答案,例如:

echo (string) $collection->getSelect();

我可能错了,但我认为因为
customer/customer
是一个EAV模型而不是一个平面模型,所以它使用的表别名是
e
而不是
main\u table

$collection->getSelect()->joinLeft(
    array('salesrep' => 'custom_column'),
    'e.entity_id = salesrep.user_id',
    array('user_id' => 'salesrep.linked_customer_id')
);
您将能够通过调试select语句来找到答案,例如:

echo (string) $collection->getSelect();

你完全正确。情况就是这样。表别名确实是
e
。谢谢你明确的回答。你完全正确。情况就是这样。表别名确实是
e
。谢谢你明确的回答。