Witam
Mam stworzoną tabelę app.users i app.position, z dodaniem rekordu nie miałem problemu ale z edycją istniejącego rekordu mam problem, szczerze to nie wiem nawet jak ugryźć ten temat, relacja jest od users Many To One a od strony position One To Many
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Entity\Permission;
/**
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Position", inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $position;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Permission", inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $permission;
/**
* @ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @ORM\Column(type="string", length=254, unique=true)
*/
private $email;
/**
* @ORM\Column(name="first_name", type="string", length=50)
*/
private $firstName;
/**
* @ORM\Column(name="last_name", type="string", length=100)
*/
private $lastName;
public function getId()
{
return $this->id;
}
public function getPosition(): ?Position
{
return $this->position;
}
public function setPosition(?Position $position): self
{
$this->position = $position;
return $this;
}
public function getPermission(): ?Permission
{
return $this->permission;
}
public function setPermission(?Permission $permission): self
{
$this->permission = $permission;
return $this;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*/
public function setUsername($username): void
{
$this->username = $username;
}
/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password): void
{
$this->password = $password;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param mixed $firstName
*/
public function setFirstName($firstName): void
{
$this->firstName = $firstName;
}
/**
* @return mixed
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param mixed $lastName
*/
public function setLastName($lastName): void
{
$this->lastName = $lastName;
}
public function getRoles()
{
return array('ROLE_'.$this->getPermission()->getName());
}
public function setRoles($role)
{
$this->permission = $role;
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized, ['allowed_classes' => false]);
}
}
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="app_position")
* @ORM\Entity(repositoryClass="App\Repository\PositionRepository")
*/
class Position
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=40)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="position")
*/
private $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setPosition($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
// set the owning side to null (unless already changed)
if ($user->getPosition() === $this) {
$user->setPosition(null);
}
}
return $this;
}
}