Difference between Model and Model Resource

Difference between Model and Model Resource

August 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Difference between Model and Model Resource

Understanding the Magento Object System: Models vs Resource Models

As you’re getting started with Magento development and coming from a Microsoft background, the concept of models and resource models might seem confusing at first glance. Let’s break down these key components in Magento’s object system.

Understanding Magento Models

In Magento, a model represents a business entity or data structure in your application. It defines the behavior and properties of an object like a product, customer, order, etc. Models are typically located under app/code/core/Mage/<ModuleName>/Model.

class Customer extends Mage_Core_Model_Abstract {
    ...
}

The base model class in Magento is Mage_Core_Model_Abstract. Every model you create should extend this abstract class, which provides basic functionality like saving and loading data from the database.

What are Resource Models?

Resource models are used to interact with the database on behalf of a regular model. They handle CRUD operations (Create, Read, Update, Delete) for the associated model.

class Customer extends Mage_Core_Model_Abstract {
    protected $_eventPrefix = 'customer_save';
    ...
}

The resource model is defined as a separate class from its corresponding model to allow for greater flexibility in data manipulation. It inherits from Mage_Core_Model_Resource_Abstract which provides methods like save, load, delete, and getReadConnection.

The Relationship between Models and Resource Models

Each model has a corresponding resource model that handles the database interaction. Magento uses the naming convention <ModuleName>_<ModelName> for both models and resource models to maintain this relationship.

For example:

  • Customer model: Mage_Customer_Model_Customer
  • Customer resource model: Mage_Customer_Model_Resource_Customer

To fetch a customer from the database using the customer model:

$customer = Mage::getModel('customer/customer');
$customer->load(1);

In this example, Magento resolves the model and its associated resource model to interact with the database.

Entity Objects and Resource Models

Entity objects are used in conjunction with resource models to represent a single row of data from a table. They extend Mage_Eav_Model_Entity_Abstract and provide methods for accessing attributes, collection management, saving, loading, etc.

class Customer extends Mage_Core_Model_Abstract {
    protected $_eventPrefix = 'customer_save';
    ...
}

Resource models use entity objects internally to perform database operations. The entity object represents the data row while the resource model handles the CRUD operations against that row in the table.

Conclusion

In summary, Magento’s object system separates concerns between business logic (models) and data persistence (resource models and entity objects). This separation allows for better code organization, extensibility, and maintainability in your application.

As you continue exploring Magento development, understanding these key components will help you build more efficient and scalable solutions. I recommend further reading on the official Magento Developers Guide.

Happy coding!

Catalog Database Extensions Orders

Our network