How to initialize a ID value in constructor class and get the las ID autoincrement in doctrine, symfony2?

StackOverflow https://stackoverflow.com/questions/23650119

  •  22-07-2023
  •  | 
  •  

Question

I have a class with field ID autoincrement

class Prueba{

/**
 * @var integer $id
 *
 * @ORM\Column(name="`id`", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

but when I try this:

public function __construct()
    {


      $this->entorno = new Entorno('MSU',$this->id);

    }

this->id is not initialize to 1 and is NULL

I want this:

if is the first new Prueba() or doctrine prueba is empty

 $this->id = 1

else

$this->id=get the last ID from table Prueba in doctrine.

How I can do?

Was it helpful?

Solution

Sorry to all, I forgot to include this in my class Entorno: * @ORM\JoinColumn(name="prueba_id", referencedColumnName="id")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top