I donโt understand why with some Entity objects I can set Id objects for others too, I get an error message and says that Id cannot be null and I have to pass the object instead.
eg:.
$log = new Log();
$log->setTypeId(1);
$log->setUserId(1);
$entityManager->persist($log);
$entityManager->flush();
If I try the code above, I get the error message: Integrity constraint violation: 1048 The user_id column cannot be zero . And I must first create a Type Object and User and pass them:
$log->setType($TypeObject)
$log->setUser($UserObject)
But for other object objects, I have no problem assigning a value directly, why?
This is my entity log:
<?php
class Log
{
protected $id;
protected $user_id;
protected $type_id;
protected $created;
protected $user;
protected $type;
public function getId()
{
return $this->id;
}
public function getUserId()
{
return $this->user_id;
}
public function getTypeId()
{
return $this->type_id;
}
public function getCreated()
{
return $this->created;
}
public function setUserId($userId)
{
$this->user_id = $userId;
}
public function setTypeId($typeId)
{
$this->type_id = $typeId;
}
public function setCreated($created)
{
$this->created = $created;
}
public function setUser($user)
{
$this->user = $user;
}
public function setType($type)
{
$this->type = $type;
}
public function prePersist()
{
$this->setCreated(new DateTime());
}
}
?>
source
share