Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:22:43+00:00 2026-06-01T23:22:43+00:00

What good is a repository pattern when you have an ORM? Example. Suppose i

  • 0

What good is a repository pattern when you have an ORM?

Example. Suppose i have the following (fictional) tables:

Table: users

pk_user_id
fk_userrole_id
username

Table: userroles

fk_userrole_id
role

Now with an orm i could simply put this in a model file:

$user = ORM::load('users', $id);

Now $user is already my object, which could easily be lazy loaded:

(would be even nicer if things are automatically singular/pluralized)

foreach ( $user->userroles()->role as $role )
{
    echo $role;
}

Now with the Repository pattern i’d had to create a repository for the Users and one for the Roles. The repository also needs all kinds of functions to retrieve data for me and to store it. Plus it needs to work with Entity models. So i have to create all of those too.

To me that looks like alot of stuff do… When i could simply get the data like i described above with an ORM. And i could store it just as easy:

ORM::store($user);

In this case it would not only store the user object to the database, but also any changes i made to the ‘Roles’ object aswell. So no need for any extra work like you need with the repository pattern…


So my question basically is, why would i want to use a repository pattern with an ORM? I’ve seen tutorials where to use that pattern (like with Doctrine). But it really just doesn’t make any sense to me… Anyone any explanation for its use in combination with an ORM..??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:22:44+00:00Added an answer on June 1, 2026 at 11:22 pm

    The ORM is an implementation detail of the Repository. The ORM just makes it easy to access the db tables in an OOP friendly way. That’s it.

    The repository abstract persistence access, whatever storage it is. That is its purpose. The fact that you’re using a db or xml files or an ORM doesn’t matter. The Repository allows the rest of the application to ignore persistence details. This way, you can easily test the app via mocking or stubbing and you can change storages if it’s needed. Today you might use MySql, tomorrow you’ll want to use NoSql or Cloud Storage. Do that with an ORM!

    Repositories deal with Domain/Business objects (from the app point of view), an ORM handles db objects. A business objects IS NOT a db object, first has behaviour, the second is a glorified DTO, it only holds data.

    Edit
    You might say that both repository and ORM abstract access to data, however the devil is in the details. The repository abstract the access to all storage concerns, while the ORM abstract access to a specific RDBMS

    In a nutshell, Repository and ORM’s have DIFFERENT purposes and as I’ve said above, the ORM is always an implementation detail of the repo.

    You can also check this post about more details about the repository pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a good example projects for using repository pattern and stored
I have two tables, as per following example, in an MSSQL db. PROJECT id
I have implemented the repository pattern using the following generic interface. public interface IRepository<T>
I have implemented a repository pattern in my asp.net mvc web application... But i
I'm getting into writing unit testing and have implemented a nice repository pattern/moq to
i'm starter in Repository Pattern in EntityFreamework in Bussiness Layer i Have Get Methods
I have a question for how to implement multiple criteria for a repository pattern
I'm looking for a good example repository of a Rails 3 project that implements
I'm trying to move toward TDD, ORM, Mocking, ect. I need a good example
I have a question regarding DDD and the repository pattern. Say I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.