Saving the Value of a Specific Attribute from a Model

In Magento, it’s very easy to save all the data in a model by running $model->save();. (Note: In this blog post, model refers to an EAV model, not a flat resource model) This saves all the attributes for the model to their respective attribute tables. There are times when saving the value of just one of the model attributes is desirable.

[cta prefix=”Related:” count=”1″][/cta]


A couple cases where you’d want to do this:

  • You’ve been passed a model from an event, and you aren’t sure if the data in that model can be safely saved.
  • You are saving many models and want to make your save operations as efficient as possible

Here is how you’d save just one attribute of a product model:

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('Some Random Name');
$product->getResource()->saveAttribute($product, 'name');

Share it


Related Posts

Everything You Need to Know About Updating to Google Analytics 4

Classy Llama is Proud to be a Sponsor of Signifyd’s #FLOWSummit2023

Classy Llama Earns 2 New Workplace Awards from

Contact Us