Hallo!
Ich beschäftige mich etwas mit Doctrine und konnte 1 Problem vermutlich bereits lösen, siehe: https://www.php.de/forum/webentwickl...en-beziehungen
Ich habe leider ein nächstes Problem
Die contact_id ist null. Im oberen Thread ich eine Beziehung zwischen der Tabelle contacts und tasks mit Doctrine herstellen.
Tabelle: Contact
Tabelle: Task
In meinem Model speichere ich die Daten so.
Alle Daten sind vorhanden und das $data-array ist auch richtig gefüllt. Ich konnte den übertragenen Wert bis ins $task->setContactId verfolgen, auch hier wird der Wert übertragen:
Die contact_id ist jedoch immer null . Ich habe 4 Stunden recherchiert und probiert und kein Erfolg. Aus meiner Sicht wird alles korrekt übertragen, aber die Datenbank erhält nicht alle Daten.
Was sehe ich wieder nicht?
Vielen Dank für die Hilfe.
MfG
Ich beschäftige mich etwas mit Doctrine und konnte 1 Problem vermutlich bereits lösen, siehe: https://www.php.de/forum/webentwickl...en-beziehungen
Ich habe leider ein nächstes Problem
( ! ) Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'contact_id' cannot be null in C:\xampp\htdocs\apps\workflow\vendor\doctrine\dbal \lib\Doctrine\DBAL\Driver\AbstractMySQLDriver.php on line 125
( ! ) Doctrine\DBAL\Exception\NotNullConstraintViolation Exception: An exception occurred while executing 'INSERT INTO tasks (contact_id, project_id, test_id, deployed_at, creator_id, priority_id, status_id, title, description, begin_at, end_at, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, 1, 1, "2020-08-03 19:00:00", 1, 1, 1, "Das ist ein Test Nr. 1", "alsdkjfa\u00f6lskjdfsaf", "2020-08-10 12:37:00", "2020-08-10 12:37:00", "2020-08-03 19:00:00", "2020-08-10 12:53:09"]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'contact_id' cannot be null in C:\xampp\htdocs\apps\workflow\vendor\doctrine\dbal \lib\Doctrine\DBAL\Driver\AbstractMySQLDriver.php on line 125
Tabelle: Contact
PHP-Code:
/**
* @ORM\Entity
* @ORM\Table(name="contacts")
*/
class Contact
{
...
/**
* @ORM\OneToMany(targetEntity="Task", mappedBy="contact")
*/
private $tasks = 0;
...
}
Tabelle: Task
PHP-Code:
/**
* @ORM\Entity
* @ORM\Table(name="tasks")
*/
class Task
{
use \Traits\IdentifiableTrait;
use \Traits\PropertiesableTrait;
use \Traits\TimestampableTrait;
/**
* Contact Id
*
* @ORM\Column(type="integer", name="contact_id")
*
* @var integer
*/
private int $contactId = 0;
/**
* @ORM\ManyToOne(targetEntity="Entities\Contact", inversedBy="tasks")
* @ORM\JoinColumn(name="contact_id", referencedColumnName="id")
*/
private $task;
public function getContactId(): int
{
return $this->contactId;
}
public function setContactId(int $id)
{
$this->contactId = $id;
}
...
}
PHP-Code:
public function create($data) {
$task = new Task;
$task->setTitle($data['title']);
$task->setDescription($data['desc']);
$task->setBeginAt($data['beginAt']);
$task->setEndAt($data['endAt']);
$task->setCreatorId(1);
$task->setPriorityId($data['priorityId']);
$task->setStatusId($data['statusId']);
$task->setContactId($data['contactId']);
$task->setProjectId(1);
$task->setTestId(1);
$task->setDeployedAt('2020-08-03T19:00');
$task->setCreatedAt('2020-08-03T19:00');
$task->setUpdatedAt();
$this->entityManager->persist($task);
$this->entityManager->flush();
}
PHP-Code:
Entities\Task;
...
public function setContactId(int $id)
{
// Bis hierher wird die $id auch korrekt befüllt
$this->contactId = $id;
}
...
Was sehe ich wieder nicht?
Vielen Dank für die Hilfe.
MfG
Kommentar