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 753479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:54:07+00:00 2026-05-14T14:54:07+00:00

Bit of an abstract problem here. I’m experimenting with the Domain Model pattern, and

  • 0

Bit of an abstract problem here. I’m experimenting with the Domain Model pattern, and barring my other tussles with dependencies – I need some advice on generating Identity for use in an Identity Map.

In most examples for the Data Mapper pattern I’ve seen (including the one outlined in this book: http://apress.com/book/view/9781590599099) – the user appears to manually set the identity for a given Domain Object using a setter:

$UserMapper = new UserMapper;

//returns a fully formed user object from record sets
$User = $UserMapper->find(1);

//returns an empty object with appropriate properties for completion
$UserBlank = $UserMapper->get();
$UserBlank->setId();
$UserBlank->setOtherProperties();

Now, I don’t know if I’m reading the examples wrong – but in the first $User object, the $id property is retrieved from the data store (I’m assuming $id represents a row id). In the latter case, however, how can you set the $id for an object if it has not yet acquired one from the data store?
The problem is generating a valid “identity” for the object so that it can be maintained via an Identity Map – so generating an arbitrary integer doesn’t solve it.

My current thinking is to nominate different fields for identity (i.e. email) and demanding their presence in generating blank Domain Objects. Alternatively, demanding all objects be fully formed, and using all properties as their identity…hardly efficient.

(Or alternatively, dump the Domain Model concept and return to DBAL/DAO/Transaction Scripts…which is seeming increasingly elegant compared to the ORM implementations I’ve seen…)

  • 1 1 Answer
  • 1 View
  • 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-05-14T14:54:08+00:00Added an answer on May 14, 2026 at 2:54 pm

    You would use the setId function if you are controlling the IDs, if you want to override the data store ID, or if you want to update/delete the data without having to retrieve it first (i.e. already have the ID from a POST).
    Another alternative would be calling setId() to reserve an ID by “querying” (insert a record) the data store for the next available ID.

    It’s not really relevant what the ID is set to until you actually need to use it to reference something. Calling setId with no parameter would do nothing except flag the object as new data. Once you actually try to “get” the ID is when one would be generated. Sort lazy ID generation.

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

Sidebar

Related Questions

Here's a bit of an abstract question. Would it be appropriate to say that
My title is a bit vauge, here's the problem I'm talking about. Say I
The problem: I need to abstract my database interaction on my application. The thing
My problem is almost exactly the same as the problem posted here: Abstract class
This may be a bit of an abstract question, so apologies in advance. I
I am bit confused in the usage of Static class, Private constructor and abstract
Bit of a tough one to explain here, but I'll do my best. I
Bit of a weird glitch here. The tag name of a childNode is logged
Bit of a strange question here i know. but i wanted to know if
This may seem a bit odd, but I really need to create a workaround

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.