api-platform / api-platform/create-client
Next gen ManyToOne error
- Linguagem predominante
- TypeScript
- Estrelas
- 376
- Forks
- 132
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
**API Platform version(s) affected**: 3.2.11
**Description**
If an entity contains a manytoone relation, the pwa/component/nameOfEntity/list.tsx generate by Next gen contains error
I have two entity : Entreprise and Meet.
**Class Entreprise**
```
['entreprise:read']],
denormalizationContext: ['groups' => ['entreprise:write']],
)]
class Entreprise
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['entreprise:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['entreprise:read', 'entreprise:write', 'user:read'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['entreprise:read', 'entreprise:write', 'user:read'])]
private ?string $address_street = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['entreprise:read', 'entreprise:write', 'user:read'])]
private ?string $address_city = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['entreprise:read', 'entreprise:write', 'user:read'])]
private ?string $address_cp = null;
#[ORM\Column(options: ['default' => 0])]
#[Groups(['entreprise:read', 'entreprise:write', 'user:read'])]
private ?int $type = null;
#[ORM\OneToMany(mappedBy: 'entreprise_id', targetEntity: Meet::class, orphanRemoval: true)]
#[Groups(['entreprise:read', 'user:read'])]
private Collection $meets;
#[ORM\OneToMany(mappedBy: 'entreprise_id', targetEntity: Customer::class, orphanRemoval: true)]
#[Groups(['entreprise:read', 'user:read'])]
private Collection $customers;
#[ORM\OneToMany(mappedBy: 'entreprise_id', targetEntity: Employee::class, orphanRemoval: true)]
#[Groups(['entreprise:read', 'user:read'])]
private Collection $employees;
#[ORM\OneToMany(mappedBy: 'entreprise_id', targetEntity: User::class)]
#[Groups(['entreprise:read'])]
private Collection $users;
```
**Class Meet**
```
['meet:read']],
denormalizationContext: ['groups' => ['meet:write']],
)]
class Meet
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['meet:read', 'entreprise:read'])]
private ?int $id = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['meet:read', 'meet:write', 'entreprise:read'])]
private ?\DateTimeInterface $date_start = null;
#[ORM\Column]
#[Groups(['meet:read', 'meet:write', 'entreprise:read'])]
private ?int $duration = null;
#[ORM\ManyToOne(inversedBy: 'meets')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['meet:read', 'meet:write'])]
private ?Entreprise $entreprise_id = null;
#[ORM\OneToMany(mappedBy: 'meet_id', targetEntity: Notification::class, orphanRemoval: true)]
#[Groups(['meet:read', 'meet:write', 'entreprise:read'])]
private Collection $notifications;
#[ORM\ManyToMany(targetEntity: Employee::class, mappedBy: 'meets')]
#[Groups(['meet:read', 'meet:write', 'entreprise:read'])]
private Collection $employees;
#[ORM\ManyToMany(targetEntity: Customer::class, inversedBy: 'meets')]
#[Groups(['meet:read', 'meet:write', 'entreprise:read'])]
private Collection $customers;
public function __construct()
{
$this->notifications = new ArrayCollection();
$this->employees = new ArrayCollection();
$this->customers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->date_start;
}
public function setDateStart(\DateTimeInterface $date_start): static
{
$this->date_start = $date_start;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(int $duration): static
{
$this->duration = $duration;
return $this;
}
public function getEntrepriseId(): ?Entreprise
{
return $this->entreprise_id;
}
public function setEntrepriseId(?Entreprise $entreprise_id): static
{
$this->entreprise_id = $entreprise_id;
return $this;
}
/**
* @return Collection
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): static
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setMeetId($this);
}
return $this;
}
public function removeNotification(Notification $notification): static
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getMeetId() === $this) {
$notification->setMeetId(null);
}
}
return $this;
}
/**
* @return Collection
*/
public function getEmployees(): Collection
{
return $this->employees;
}
public function addEmployee(Employee $employee): static
{
if (!$this->employees->contains($employee)) {
$this->employees->add($employee);
$employee->addMeet($this);
}
return $this;
}
public function removeEmployee(Employee $employee): static
{
if ($this->employees->removeElement($employee)) {
$employee->removeMeet($this);
}
return $this;
}
/**
* @return Collection
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): static
{
if (!$this->customers->contains($customer)) {
$this->customers->add($customer);
}
return $this;
}
public function removeCustomer(Customer $customer): static
{
$this->customers->removeElement($customer);
return $this;
}
}
```
pwa/components/meet/list.tsx
```
import { FunctionComponent } from "react";
import Link from "next/link";
import ReferenceLinks from "../common/ReferenceLinks";
import { getItemPath } from "../../utils/dataAccess";
import { Meet } from "../../types/Meet";
interface Props {
meets: Meet[];
}
export const List: FunctionComponent = ({ meets }) => (
Meet List
Create
{meets &&
meets.length !== 0 &&
meets.map(
(meet) =>
meet["@id"] && (
)
)}
id
date_start
duration
entreprise_id
notifications
employees
customers
{meet["date_start"]?.toLocaleString()}
{meet["duration"]}
{console.log()}
({
href: getItemPath(ref, "/entreprises/[id]"),
name: ref,
}))}/>
({
href: getItemPath(emb["@id"], "/notifications/[id]"),
name: emb["@id"],
}))}
/>
({
href: getItemPath(ref, "/employees/[id]"),
name: ref,
}))}
/>
({
href: getItemPath(ref, "/customers/[id]"),
name: ref,
}))}
/>
Show
Edit
);
```
**Possible Solution**
Error TypeError: meet.entreprise_id.map is not a function come from this code
```
({
href: getItemPath(ref, "/entreprises/[id]"),
name: ref,
}))}/>
```
meet["entreprise_id"] is not an array so it's impossible to map it
It's possible to solve with
``` ({
href: getItemPath(ref, "/entreprises/[id]"),
name: ref,
}))}/>```
**Additional Context**
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.