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

The Archive Base Latest Questions

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

All my Doctrine2 setups are done within YAML files. I have an entity class

  • 0

All my Doctrine2 setups are done within YAML files. I have an entity class named LoanAppMenuProgress where I’m trying to execute a prePersist function. This LoanAppMenuProgress entity has a oneToOne relationship with another class named LoanApp. There is a foreign key association on the LoanAppMenuProgress table associated with the LoanApp table in the DB.

I have this config for my LoanAppMenuProgress class in LoanApp.LoanAppMenuProgress.orm.yml:

LoanEv\LoanAppBundle\Entity\LoanApp\LoanAppMenuProgress:
  type:  entity
  repositoryClass: LoanEv\LoanAppBundle\Repository\LoanApp\LoanAppMenuProgress
  table: loan_app_menu_progress
  id:
    id:
      type: integer
      generator: { strategy: auto }

### This is the OWNING side of the relationship
  oneToOne:
    loan_app:
      targetEntity: LoanApp
      inversedBy: loanapp_menu
      joinColumn:
        name: loan_id
        referencedColumnName: id

  fields:
    loan_id:
      type: integer
    menu_id2:
      type: integer
    menu_id3:
      type: integer
    menu_id4:
      type: integer

  lifecycleCallbacks:
    prePersist: [ updateMainMenuStatus ]

This is my LoanApp.LoanApp.orm.yml file:

LoanEv\LoanAppBundle\Entity\LoanApp\LoanApp:
  type:  entity
  repositoryClass: LoanEv\LoanAppBundle\Repository\LoanApp\LoanAppRepository
  table: loan_app
  id:
    id:
      type: integer
      generator: { strategy: auto }

## This is the INVERSE side of the relationship.
  oneToOne:
    loanapp_menu:
      targetEntity: LoanAppMenuProgress
      mappedBy: loan_app

  fields:
    bank_id:
      type: integer
  # etc.

In my LoanAppMenuProgress Entity class, I have the following code:

namespace LoanEv\LoanAppBundle\Entity\LoanApp;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Util\Debug;

/**
 * LoanEv\LoanAppBundle\Entity\LoanApp\LoanAppMenuProgress
 */
class LoanAppMenuProgress
{
    private $id;

    private $loan_id;

    /**
     * @var LoanEv\LoanAppBundle\Entity\LoanApp\LoanApp
     */
    private $loan_app;

    private $menu_id2 = 0;

    private $menu_id3 = 0;

    private $menu_id4 = 0;

    // ...

    public function updateMainMenuStatus()
    {       
        echo("Inside prePersist's updateMainMenuStatus function. ");
    }
}

The following code is called from within my LoanAppController class:

// ...

//Save the menuStatus changes.
echo("About to persist. ");
    $em->persist($menuStatus[0]);
echo("Done persisting.");
    $em->flush();

// ...

When I execute the code in the LoanAppController the following gets written to my screen:

“About to persist. Done persisting.”

I’m missing that bit in the middle where the output should read:

“About to persist. Inside prePersist’s updateMainMenuStatus function. Done persisting.”

The changes ARE getting written to the database, and all the functionality of the system is working as expected with the exception of the prePersist(). I’ve struggled with the yml setups for quite a while so my initial assumption is that my YAML setup is incorrect.

The documentation (as far as I could understand it) mentions that I should add the lifecycleCallbacks: and prePersist: items to the yml file, and then make sure I have a public function in the persisting Entity. Obviously, I’m missing something.

Does anyone have any ideas?

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-05-26T02:10:10+00:00Added an answer on May 26, 2026 at 2:10 am

    prePersist only gets called when you are performing an INSERT type statement. This event will never fire on an UPDATE action.
    To perform some action when an entity is being UPDATEd, use preUpdate. Note, that preUpdate has far more restrictions on what can be performed with the entity in question.

    Derrick

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

Sidebar

Related Questions

How (if possible at all) do you change the entity type with Doctrine2, using
Im using Doctrine2 and I have a fair amount of model Objects. All the
All I am trying to do is take a standard range on an excel
I'm trying to do an association of 5 objects with Doctrine2 (PHP). I'm using
When I execute the command './doctrine build-all-reload' It comes out the following output: build-all-reload
I am developing using zend framework and doctrine2.1. I have generated entities from database.
Let's say I have a User class : $user = new User(1); $user->setName('Bob'); //
I have a few simple classes, all extending Doctrine_Record. Now I want to make
all. I would like to ask if it is possible to have multiple forms
I am trying to get all users who logged in last day. How can

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.