Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

delete multiple rows by non-pk column name
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

I wrote the code

$model_base->load($product_id'product_id');
$model_base->Delete();
the outputted sql log is:
## 5500 ## QUERY
SQLSELECT `xx_price`.* FROM `xx_priceWHERE (xx_price.product_id='179')
AFF2
TIME
0.0011

## 5500 ## QUERY
SQLDELETE FROM `xx_priceWHERE (id='4')
AFF1
TIME
0.0005

and it only delete the 1st row for me, how can I delete all the rows loaded?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

After exploring the save() function, I knew that it only called $data = $read->fetchRow($select) one time, so it only load the 1st row. But how can I load all the rows? it seems that Zend_Db_Adapter_Abstract::fetchAll() will do that, but dose magento have an API that use this function?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

I got a way to do it

do
{
    $model_base     
Mage::getModel('xx/price');
    
$model_base->load($product_id'product_id');
    
$model_base->Delete();
}
while($model_base->hasData());
but is seems very inefficient, I hope there is a better way.
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top