I am facing an issue with deleting rows from table by custom field.

Below my database table

link_id | quote_id  | giftcard_value | giftcard | redeemed_at
10000   | 20000     | 450            | XSERTTY3 | 2015-12-01
10001   | 20000     | 600            | DSFDTTY3 | 2015-12-01

I need to delete all the entries by quote_is.

My code is like this


But its working for one entry, but not working for may entries. Please help me


No need to load the entire entities it is not optimal in terms of performance.

You should use collections instead:

$collection = Mage::getResourceModel('xxxxxxxxxx/xxxxxxxxxx_collection')->addFieldToFilter('quote_id', $quote->getId());
foreach ($collection as $item) {
  • Its giving PHP Fatal error: Call to undefined method xxxx_xxxx_Model_Resource_xxxxx_Collection::delete() – Rinto George Jul 27 '16 at 13:08
  • @duke see my update – Raphael at Digital Pianism Jul 27 '16 at 13:21

Here ->load($quote->getId(),'quote_id') may return multiple rows, so if you do ->delete() on this collection, ONLY first row will be deleted.

You should loop through the collection for deleting all fetched rows :

$items = Mage::getModel('xxxxxxxxxx/xxxxxxxxxx')->load($quote->getId(),'quote_id');
foreach($items as $item){

Otherwise, I have heared about deleteAll method (BUT I've never tried it) :

//Not sure, but Give it a try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.