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

  • SEARCH
  • Home
  • 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 9077975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:30:23+00:00 2026-06-16T19:30:23+00:00

I have recently started reading about data mappers and all the articles I’ve found

  • 0

I have recently started reading about data mappers and all the articles I’ve found only demonstrate CRUD operations like:

$user = new User('John', 'Joe', 'john@hotmail.com');
$userMapper->insert($user);

// or this...
$user = $userMapper->fetchById(239);

Surely they are supposed to do more?

Currently in my application I use DAO’s (or something similar anyway) so for example when I need a $user object one of my factories creates a $userDAO object and injects it into my $user object. And to do a query from my $user object I just do:

$this->userDAO->getNumActiveOrders($this->userId);

and it will do the query in the $userDAO object and return the result.

After loads of reading it seems my implementation is wrong because the domain object should not know about the DAO and vice versa. Am I right or wrong?

If it’s wrong to do it that way then I assume that data mappers must be used for more than CRUD operations?

So if I wanted to find out how many active orders a user has I can do something like:

$userMapper->getNumActiveOrders($userId);

Would that be correct?

And if I wanted to set that value in my $user object I would have to do something like:

$user->setNumActiveOrders($userMapper->getNumActiveOrders($userId));

Using my implementation of DAO’s seems to be a lot faster and uses less code than using data mappers but I am probably implementing data mappers wrongly.

Any advice would be great thanks.

  • 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-16T19:30:24+00:00Added an answer on June 16, 2026 at 7:30 pm

    After loads of reading it seems my implementation is wrong because the domain object should not know about the DAO and vice versa. Am I right or wrong?

    That is correct.

    If it’s wrong to do it that way then I assume that data mappers must be used for more than CRUD operations?

    The purpose of a DataMapper is to map data from a Database to Domain Objects. Since object graphs are usually not structured like data in a relational database system, you need some sort of mapper to get the relational data from the database into your objects and vice versa. DataMappers try to solve the problem of Impedance Mismatch.

    So if I wanted to find out how many active orders a user has I can do something like:

    $userMapper->getNumActiveOrders($userId);
    

    Would that be correct?

    Yes, you could it do it that way. But you could also query the user object for it, e.g.

    echo $user->getActiveOrders();
    

    and your user object would likely have some sort of Lazy Loading mechanism to fetch the Active Orders then.

    And if I wanted to set that value in my $user object I would have to do something like:

    $user->setNumActiveOrders($userMapper->getNumActiveOrders($userId));
    

    No. You’d simply set the Active Orders. The number can be derived from them. If the count is something you want inserted in the database, you’d handle that in the Mapper.

    Using my implementation of DAO’s seems to be a lot faster and uses less code than using data mappers but I am probably implementing data mappers wrongly.

    That’s pretty much normal, because DAO’s only query the database and don’t do any mapping.

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

Sidebar

Related Questions

I have never used multiple inheritance but while reading about it recently I started
I have recently started reading about Java EE6 and in the examples I follow
I have only recently started programming significantly, and being completely self-taught, I unfortunately don't
I have recently started to look at sql reporting services. I have data stored
I have recently started reading up on Grails and would like to use SQL
I have recently started reading Programming Challenges book by S. Skiena and believe or
I recently started learning about IPC and I have some issues. I wrote a
I have recently started reading into annotations. I deprecated the armStrong() method here and
I recently started reading through Paul Graham's On Lisp with a friend, and we
I have recently started learning C++, but I require a compiler. I have tried

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.