Witam.
Przerabiam sobie pewien tutorial z youtube i dokłądnie w miejscu do którego dałem link:
https://www.youtube.com/watch?v=MS4LICZ1j0s&t=251sNapotykam na problem. Pojawia się komunikat:
Cytat
In SchemaException.php line 44:
Invalid index-name cat-id given, has to be [a-zA-Z0-9_]
Z tego co rozumie, to komunikat ten mówi, że index o nazwie cat-id jest niepoprawny, z tego co widzę znak "-" jest niedozwolony.
Dziwna sprawa, bo tylko dodałem dwie encje poprzez bin/console tak jak na filmie. Dodałem klucz obcy dla dwóch encji i pojawia się ten błąd. Robie dokłądnie to co w tutorialu.
<?php
//plik Post.php
namespace App\Entity;
use App\Repository\PostRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PostRepository::class)
*/
class Post
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $content;
//tutaj $category dodana recznie
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="posts")
*/
private $category;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
}
<?php
//Plik Category.php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
//tutaj $posts dodana recznie
/**
* @ORM\OneToMany(targetEntity="Post", mappedBy="category")
*/
private $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Posts[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Posts $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCategory($this);
}
return $this;
}
public function removePost(Posts $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getCategory() === $this) {
$post->setCategory(null);
}
}
return $this;
}
}
Co robie nie tak, czy mogę gdzies podać nazawę tego klucza? Próbowałem różne kombinacje, i juz brak pomysłów.
Ten post edytował starterrrrr 8.02.2021, 11:52:50