Saving the Value of a Specific Attribute from a Model
Saving the Value of a Specific Attribute from a Model

Saving the Value of a Specific Attribute from a Model

Published February 10, 2010 in Development
PHP Single vs. Double Quotes
February 7, 2010
The Smart Method of Loading Collections
February 10, 2010

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.

 

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:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Recent PostsView all
November 6, 2019

Three Ways BigCommerce is “Thinking Big”

Three Ways BigCommerce is “Thinking Big” At the end of October, BigCommerce hosted its Partner Summit in Austin, TX. I flew down early to hang out […]
November 5, 2019

Marlow White Magento 1 to Magento 2 Migration

October 28, 2019

Putting the Focus on Post-Purchase: A Guide to Perfecting Transactional Email Campaigns

When it comes to building an online retail brand, few things are more important than building a base of customers. And with rising competition meeting you […]