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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:21:51+00:00 2026-06-02T18:21:51+00:00

I am having trouble persisting a null which is already persisted with an object.

  • 0

I am having trouble persisting a null which is already persisted with an object.

It throws the following error.

Catchable Fatal Error: Argument 1 passed to MyProject\EntityBundle\Entity\Requirements::setReplacedEmployee() must be an instance of MyProject\EntityBundle\Entity\Employee, null given, called in /var/www/MyProject/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/MyProject/src/MyProject/EntityBundle/Entity/Requirements.php line 384

Initially i save the replacedEmployee object which could be null/object. But later on if i replace the object with a null while editing it throws the above error.

The below is my code from the controller.

try {
            if ($request->request->get('save') === 'Save') {

                $form->bindRequest($request); // this is the line which throws the above error

                if ($form->isValid()) {
                    $requirementObj->setUpdatedAt(new \DateTime('now'));
                    $em->flush();
                    $request->request->set('requirementId', $requirementId);
                    return $this->displayAction($request);
                }
            }
        }

This is the content in Requirements.php which is an entity file.

 /**
 * @var replacedEmployee
 *
 * @ORM\ManyToOne(cascade={"persist"},targetEntity="Employee")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="replaced_employee_id",referencedColumnName="id",onDelete="CASCADE")
 * })
 */
private $replacedEmployee;


 /**
 * Set replacedEmployee
 *
 * @param MyProject\EntityBundle\Entity\Employee $replacedEmployee
 */
public function setReplacedEmployee(\MyProject\EntityBundle\Entity\Employee $replacedEmployee)
{
    $this->replacedEmployee = $replacedEmployee;
}

/**
 * Get replacedEmployee
 *
 * @return MyProject\EntityBundle\Entity\Employee 
 */
public function getReplacedEmployee()
{
    return $this->replacedEmployee;
}

Can anybody Suggest a solution to this problem.

Thanks in advance.

  • 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-02T18:21:52+00:00Added an answer on June 2, 2026 at 6:21 pm

    I can’t fully understand your question but, if you want to allow null values for the relation with Employee you should first edit the mapping (this maybe not necessary as JoinColumn should allow null values by default):

     /**
     * @var replacedEmployee
     *
     * @ORM\ManyToOne(cascade={"persist"},targetEntity="Employee")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(
     *     name="replaced_employee_id",referencedColumnName="id",onDelete="CASCADE",
     *     nullable=true
     *   )
     * })
     */
    private $replacedEmployee;
    

    After generating setters/getters Doctrine2 (if i remember correctly, starting from 2.2.1) should generate:

     /**
     * Set replacedEmployee
     *
     * @param MyProject\EntityBundle\Entity\Employee $replacedEmployee
     */
    public function setReplacedEmployee(Employee $replacedEmployee = null)
    {
        $this->replacedEmployee = $replacedEmployee;
    }
    

    Note that argument is optional (has null default value). Hope this helps.

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

Sidebar

Related Questions

Having trouble using libstatgrab -- I receive the following error at compile time: libstatgrabTest.cpp:16:
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
Maybe it's been a long day but I'm having trouble persisting a collection backed
Having trouble installing play! on windows. Following the installation guide on: http://www.playframework.org/documentation/1.2.4/install After installing
Having trouble with the db.alter command when changing a date field from null=True and
Having trouble with this jQuery function: $(#content).siblings().each(function(i){ heightOfSiblings = heightOfSiblings + this.outerHeight(); }); Error
Having trouble converting the following code from dealing with IDs to Classes. Basicly what
Having trouble working out how to do the following - I want to list
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder

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.