I want to insert a column into my db table, but only if it does not exist, yet. So I thought I'd check if the model with the specified email exists, and if not I perform save() method.

Here is what I do:

$customerModel = Mage::getModel('custom/customerobject');
$loadedModel = $customerModel->load($RequestParams['email'],'email'); 
$customerIsUnique = empty($loadedModel->getData('email'));

    // Do stuff

Is this the common way how it's done in magento or is there a better way, like $customerModel->saveOnlyIfItDoesNotExistOrAnyOtherAwesomeMethod() ?

Thanks in advance

1 Answer 1


you check it like that..

                          ->addFieldToFilter('email', array('eq' => $RequestParams['email']));
        Mage::getSingleton('core/session')->addError('Email Already Registered');

    }else { // do your code here }
  • thanks :) I implemented my own error object like Mage::getSingleton('custom/statusobject')->setMessage('foo'); but after the redirect this is gone maybe you can also give me a hint or should I open new question?
    – xhallix
    Nov 12, 2015 at 12:01
  • this is global message built in module for diplaying message i think you use that or otherwise you have to use core session. to display. Nov 12, 2015 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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