У меня проблема с моим кодом.Это о ресторане.У меня есть два объекта с отношением «многие ко многим»: продукты и дни.Когда я пытаюсь создать День, я получаю эту ошибку: «Не удалось создать объект: App \ Entity \ Day \ Day».Где я не прав?
Я положил код для сущностей здесь.Если вам нужно больше, просто скажите мне.Я не думаю, что это со стороны администратора.
Вот сущность Продукта:
<?php
namespace App\Entity\Product;
use App\Entity\Category\Category;
use App\Entity\Day\Day;
use App\Entity\ProductEntry\ProductEntry;
use App\Entity\Restaurant\Restaurant;
use App\Entity\Schedule\Schedule;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Class Product
* @ORM\Entity(repositoryClass="App\Repository\Product\ProductRepository")
* @ORM\Table(name="products")
* @package App\Entity\Product
*/
class Product
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* @var \DateTime
*
* @ORM\Column(name="added_date", type="datetime", nullable=false)
*/
private $addedDate;
/**
* @var boolean
*
* @ORM\Column(name="availability", type="boolean", nullable=true)
*/
private $availability;
/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="App\Entity\Category\Category", inversedBy="products", cascade={"persist"})
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private $category;
/**
* @var float
*
* @ORM\Column(name="price", type="float", length=255, nullable=true)
*/
private $price;
/**
* @var ProductEntry
*
* @ORM\OneToMany(targetEntity="App\Entity\ProductEntry\ProductEntry", mappedBy="originalProduct", cascade={"persist"})
* @Serializer\Exclude()
*/
private $productsEntries;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Schedule\Schedule", inversedBy="products", cascade={"persist"})
* @ORM\JoinColumn(name="schedule_id", referencedColumnName="id", onDelete="CASCADE")
*
* @var Schedule
*/
private $schedule;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Restaurant\Restaurant", inversedBy="products", cascade={"persist"})
* @ORM\JoinColumn(name="restaurant_id", referencedColumnName="id", onDelete="CASCADE")
*
* @var Restaurant
*/
private $restaurant;
/**
* @var Day
*
* @ORM\ManyToMany(targetEntity="App\Entity\Day\Day", mappedBy="products", cascade={"persist"})
*/
private $days;
public function __toString()
{
return $this->name ?: "";
}
public function __construct()
{
$this->addedDate = new \DateTime();
$this->days = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getAddedDate()
{
return $this->addedDate;
}
/**
* @param mixed $addedDate
*/
public function setAddedDate($addedDate)
{
$this->addedDate = $addedDate;
}
/**
* @return bool
*/
public function isAvailability()
{
return $this->availability;
}
/**
* @param bool $availability
*/
public function setAvailability($availability)
{
$this->availability = $availability;
}
/**
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* @param float $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* @return Category
*/
public function getCategory()
{
return $this->category;
}
/**
* @param Category $category
*/
public function setCategory($category): void
{
$this->category = $category;
}
/**
* @return ProductEntry
*/
public function getProductsEntries()
{
return $this->productsEntries;
}
/**
* @param ProductEntry $productsEntries
*/
public function setProductsEntries(ProductEntry $productsEntries): void
{
$this->productsEntries = $productsEntries;
}
/**
* @return Schedule
*/
public function getSchedule()
{
return $this->schedule;
}
/**
* @param Schedule $schedule
*/
public function setSchedule(Schedule $schedule): void
{
$this->schedule = $schedule;
}
/**
* @return Restaurant
*/
public function getRestaurant()
{
return $this->restaurant;
}
/**
* @param Restaurant $restaurant
*/
public function setRestaurant(Restaurant $restaurant): void
{
$this->restaurant = $restaurant;
}
/**
* @return Day
*/
public function getDays()
{
return $this->days;
}
/**
* @param Day $days
*/
public function setDays(Day $days): void
{
$this->days = $days;
}
}
Вот сущность Дня:
<?php
namespace App\Entity\Day;
use App\Entity\Product\Product;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Day
* @package App\Entity\Day
* @ORM\Entity(repositoryClass="App\Repository\Day\DayRepository")
* @ORM\Table(name="days")
*/
class Day
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", nullable=false)
*/
private $name;
/**
* @var \DateTime
*
* @ORM\Column(name="current_date", type="datetime", nullable=false)
*/
private $currentDate;
/**
* @var \DateTime
*
* @ORM\Column(name="max_date", type="datetime", nullable=true)
*/
private $maxDate;
/**
* @var Product
*
* @ORM\ManyToMany(targetEntity="App\Entity\Product\Product", inversedBy="days", cascade={"persist"})
* @ORM\JoinTable(name="product_day",
* joinColumns={@ORM\JoinColumn(name="day_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")})
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return \DateTime
*/
public function getCurrentDate()
{
return $this->currentDate;
}
/**
* @param \DateTime $currentDate
*/
public function setCurrentDate(\DateTime $currentDate): void
{
$this->currentDate = $currentDate;
}
/**
* @return \DateTime
*/
public function getMaxDate()
{
return $this->maxDate;
}
/**
* @param \DateTime $maxDate
*/
public function setMaxDate(\DateTime $maxDate): void
{
$this->maxDate = $maxDate;
}
/**
* @return Product
*/
public function getProducts()
{
return $this->products;
}
/**
* @param Product $products
*/
public function setProducts(Product $products): void
{
$this->products = $products;
}
}