I've been working on a custom module that has a backend for admin. Until now it has been working perfectly, just like the customer modules do, but now I'm stuck with this. My custom table saves the customer ID and I can show the customer name in every row of the grid. So far I'm able to show the ID, I know that I should prepare the collection, but I don't have a clue. If I use join it only works for models of the same module. I've tried this:
$collection = Mage::getModel('mymodule/mymodel')->getCollection()->getSelect()
->join(
'customer_entity',
'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'));
If i print the query looks like this
SELECT `main_table`.*, `customer_entity`.`email` AS `customer_name` FROM
`uhma_comunidad_question` AS `main_table` INNER JOIN `customer_entity` ON
main_table.customer_id = customer_entity.entity_id
but is returning nothing, the collection is null, if i copy this sql and paste it in phpmyadmin it works perfect, what i'm i missing here
Thanks for the help.
simple, if you use chaining for getSelect() it didn't work, just added another line
$collection = Mage::getModel('mymodule/mymodel')->getCollection();
$collection->getSelect()
->join(
'customer_entity',
'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'));
it work perfect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With