Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Symfony validator don't with this bundle #44

Closed
kevinG73 opened this issue Apr 24, 2021 · 1 comment
Closed

The Symfony validator don't with this bundle #44

kevinG73 opened this issue Apr 24, 2021 · 1 comment

Comments

@kevinG73
Copy link

Hello ,
I tried to use Constraints such as : length or NotBlank
but it seems be ignored

AreaTranslation.php

/**
 * @ORM\Entity()
 */
class AreaTranslation extends AbstractTranslation
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"Area_read","Area_write"})
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Area", inversedBy="translations")
     * @Assert\NotNull
     */
    protected $translatable;

    /**
     * @ORM\Column(type="string", length=255)
     * @Assert\NotBlank()
     * @Assert\Length(max=1500)
     * @Groups({"Area_read","Area_write","translations"})
     */
    private $name;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank
     * @Assert\Language
     * @Groups({"Area_read","Area_write","translations"})
     */
    protected $locale;

    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;
    }
}
@orangevinz
Copy link

orangevinz commented Aug 29, 2022

If you want to validate nested items, you must add the @Assert\Valid at the property level this way

/**
 * @ORM\Entity()
 */
class Area extends AbstractTranslatable
{
     /**
     * @Assert\Valid
     * @ORM\OneToMany(targetEntity="App\Entity\AreaTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
     * @Groups({"your_custom_group_read", "your_custom_group_write", "translations"})
     */
    protected $translations;
}

Reference: https://stackoverflow.com/a/60431468/12750122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants