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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:25:10+00:00 2026-05-26T04:25:10+00:00

I am using Doctrine 2 entities. We have some entities which have to update

  • 0

I am using Doctrine 2 entities. We have some entities which have to update related items when they are saved to the database. For example, when a user record is modified, we save it as a new record, with the “inactive” field set to ‘false’. However, we have to set the the ‘inactive’ field for all previous record for that user to ‘true’. This is done to keep an audit history. It is a Legacy database, so changing the structure is not an option.

Since Doctrine saves objects by passing them to a persister object (persist::($thisObj)), rather than the object having a save method ($thisObj->save()), we can’t just extend a ‘save’ method from a parent object. The only option I see here is to try to extend the ‘persist’ object, but that sounds like a goose gaggle, just waiting to happen.

I found some information on events, but do not see how to add them to make events fire a particular function when a particular entity is persisted.

How do I add pre-save/post-save functionality to some of my entities ?

  • 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-05-26T04:25:11+00:00Added an answer on May 26, 2026 at 4:25 am

    So, you probably already know http://www.doctrine-project.org/docs/orm/2.1/en/reference/events.html right?

    You add an annotation that the entity contains callbacks and then create specific functions (which need to be public) on that entity and also annotate them with @PrePersist or @PostPersist or whatever.

    The other way is creating an event subscriber, register that one with the doctrine event manager and implement methods called prePersist, postPersist etc. They get passed an EventArguments object which contains the entity relevant for the occurred event.

    I know this is a very general answer to your question, but you need to be a bit more specific where your problem lies.

    Please dont exend the entity manager and overwrite the persist method, there are way cleaner methods for doing what you need as far as I can tell.

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

Sidebar

Related Questions

I have some models witch are using Doctrine nestedset feature. I want to add
I have three Doctrine entities: Device, which has a OneToOne relationship with Device\Status, which
I am developing using zend framework and doctrine2.1. I have generated entities from database.
Using Doctrine PHP If I have a user with a many to many relationship
I'm using Doctrine 2 ORM and I have this problem. I have three Entities,
I'm using Kohana 3 and have a /doctrine/Entites folder with my entities inside. When
How to create reasonable expression to store password in database using Doctrine and Zend_Auth::setCredentialTreatment()
Entities in symfony 2 have doctrine tags that are preceded with @ORM\ (eg @ORM\Entity).
Using Doctrine in symfony 1.4 I have several boolean columns defined (stored as a
I am having a problem with inserting a new row in database using Doctrine

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.