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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:55:45+00:00 2026-06-15T21:55:45+00:00

A few minutes ago I found an error in Doctrine2. I added some fields

  • 0

A few minutes ago I found an error in Doctrine2.

I added some fields in my entity, then refresh the mysql table and going to persist ago I noticed that the new data is not stored in the table.

Tried a var_dump the value of “->getXXX()” and the result was correct.

Here is the code used:

$user->setName($name);
$user->setSurname($surname);

if($country)
   $user->setCountry($country->getId());

//New code 

if($province > 0)
    $user->setProvince($province);

if($town > 0)
    $user->setTown($town);

var_dump($user->getProvince(), $user->getTown()); //Works OK

$em->persist($user); // Only persists values before Province.
$em->flush();

Thank’s and regards!


Edited

Information about my Entity:

class Users
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=50)
     */
    private $name;

    /**
     * @var string $surname
     *
     * @ORM\Column(name="surname", type="string", length=95)
     */
    private $surname;

    /**
     * @var string $mail
     *
     * @ORM\Column(name="mail", type="string", length=80, unique=true)
     */
    private $mail;

    /**
     * @var string $password
     *
     * @ORM\Column(name="password", type="string", length=255)
     */
    private $password;

    /**
     * @var $country
     *
     * @ORM\Column(name="country", type="integer")
     */
    private $country;

    /**
     * @var $province
     *
     * @ORM\Column(name="province", type="integer")
     */
    private $province;

    /**
     * @var $town
     *
     * @ORM\Column(name="town", type="integer")
     */
    private $town;
}

Country, province and town are id’s from tables with the same names. I’ve tried to change the type of the field with a ManytoOne assosiation, but it gets me an error on the Doctrine2 generated SQL. It’s seem to be a cache error, but I can’t solve it.

  • 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-15T21:55:46+00:00Added an answer on June 15, 2026 at 9:55 pm

    You have a lot to learn on how Doctrine associations work. I suggest taking some time and really reading through the Doctrine mapping documentation.

    Your User entity shouldn’t be using integers like that. You probably want a ManyToOne relationship for those instead (meaning: Each user can have exactly one country and one province). You should start thinking of things as objects and try not to pass around ID’s

    For example:

    /**
     * @ORM\ManyToOne(targetEntity="Country")
     * @ORM\JoinColumn(name="countryId", referencedColumnName="id")
     */
    private $country;
    
    /**
     * @ORM\ManyToOne(targetEntity="Province")
     * @ORM\JoinColumn(name="provinceId", referencedColumnName="id")
     */
    private $province;
    

    The targetEntity in each of those should be changed to whatever your entities are called.

    If you attempt these changes make sure you run the app/console doctrine:schema:update command to have your schema updated automatically.

    Then you can do this in your controller:

    $country = new Country('US');
    $entityManager->persist($country);
    $user->setCountry($country);
    

    Note: I didn’t assign the country ID to the setCountry() method. I pass in the actual Country object. This is just an example, and in your actual controller the $country variable here would have been passed in via a form or fetched from the database, etc.

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

Sidebar

Related Questions

A few minutes ago, I commited some files and then pushed them to my
Regarding the same program as my question a few minutes ago ... I added
a few minutes ago I had a discussion with my boss and want now
I was a bit surprised a few minutes ago when I tried to overload
THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and
I've spent a few minutes manually re-ordering fields in a struct in order to
Possible Duplicate: JIT compiler vs offline compilers So until a few minutes ago I
I was answering a question a few minutes ago and it raised to me
i just asked a question few minutes ago which led me to this one
This is another question related to a question I asked a few minutes ago.

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.