Something wrong with relations
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- php, symfony, typescript
Research direction
Start with App.js and the HydraAdmin relation form for ProposalParam, then inspect the network request generated when selecting ProposalType. Compare the field metadata with the entity relation and API response; the issue is resolved when the ManyToOne field submits a ProposalType IRI rather than a nested array.
Written by the indexing model from the issue text.
Description
PHP: 8.2
Symfony: ^6
Api platform: ^3.2
Admin api platform: ^3.4.4
I created entity ProposalType.php
#[ORM\OneToMany(mappedBy: 'proposalType', targetEntity: ProposalParam::class)]
private Collection $proposalParams;
public function __construct()
{
$this->proposalParams = new ArrayCollection();
}
public function getProposalParams(): Collection
{
return $this->proposalParams;
}
public function addProposalParam(ProposalParam $proposalParam): static
{
if (!$this->proposalParams->contains($proposalParam)) {
$this->proposalParams->add($proposalParam);
$proposalParam->setProposalType($this);
}
return $this;
}
public function removeProposalParam(ProposalParam $proposalParam): static
{
if ($this->proposalParams->removeElement($proposalParam)) {
// set the owning side to null (unless already changed)
if ($proposalParam->getProposalType() === $this) {
$proposalParam->setProposalType(null);
}
}
return $this;
}
And another entity ProposalParam.php
#[ORM\ManyToOne(inversedBy: 'proposalParams')]
#[ORM\JoinColumn(nullable: false)]
private ?ProposalType $proposalType = null;
public function getProposalType(): ?ProposalType
{
return $this->proposalType;
}
public function setProposalType(?ProposalType $proposalType): static
{
$this->proposalType = $proposalType;
return $this;
}
This is pretty simple ManyToOne relation. Generated by make:entity. I'm dont modified this.
Wanted that ProposalParam entity has ProposalType entity by relation, it is simple.
I can create ProposalType via api platform with POST request to /api/proposal_types. And it is successfull.
Then i can set this ProposalType in ProposalParam via POST request to /api/proposal_types. And it is successfull.
Records are inside database and set up like needed.
When i go to admin panel and send request to create ProposalParam i can set ProposalType.
But request sends as array
And error occured Nested documents for attribute "proposalType" are not allowed. Use IRIs instead.
And this is expected, we send array, but api wants IRI.
App.js in admin pretty standart, do not modify something
import { HydraAdmin } from "@api-platform/admin";
export default () => (
<HydraAdmin entrypoint="http://localhost:9191/api" />
);
Main goal is why system generate select where i need to specify array of ProposalTypes, instead of one ProposalType. Can someone help with it?
- Dominant language
- TypeScript
- Stars
- 516
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/admin
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
api-platform/admin#616 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
api-platform/admin#660 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
api-platform/admin#659 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
api-platform/admin#631 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
api-platform/admin#626 · 1 comment · 1 reaction ·
All issues in api-platform/admin
Similar issues
-
clawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
supermomonga/zcode-acp#24 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
growthbook/growthbook#7100 ·
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100