Magento resource model not working -
i have following code:
$recipients = mage::getresourcemodel('crm/crm_collection'); $recipients->getselect() ->joininner(array( 'link' => $recipients->gettable('crm/bulkmaillink'), ), "link.crm_id = e.entity_id", array( 'link_id' => 'link.id', )) ->where("link.queue_id = ? , link.sent_at null", $queue->getid()); $recipients->addattributetoselect('title'); $recipients->addattributetoselect('first_name'); $recipients->addattributetoselect('chinese_name'); $recipients->addattributetoselect('last_name'); $recipients->addattributetoselect('email1'); $recipients->addattributetofilter('email1', array('neq'=>'')); $recipients->setpagesize(100); $recipients->setcurpage(1); i log select statement code produces:
mage::log("debug: ".((string)$recipients->getselect())); the above produces working sql query executes in phpmyadmin , returns results expect.
i log count of $recipients
mage::log("loading recipients queue: {$recipients->count()}"); and code stops. in actual fact not log message. if comment out above logging code , try
foreach ($recipients $crm) { var_dump($crm); die(); } it not foreach. parser stop before foreach.
and worst no error messages printed. stuck.
thank you
both count() , foreach operations trigger collection load(), meaning query executed, result set fetched, , each result attempted set _data on instance of collection's model class. after item realized, collection class attempts add internal storage via additem().
i suspect collection explicitly throwing exception because there duplicate primary keys in result set; see varien_data_collection::additem() logic. comment out temporarily test.
to resolve, change query or override additem() locally in collection class.
Comments
Post a Comment