Hi devs,
I have serious trouble with the Collection Constrain.
After several threads and post in different medias and reading docs,
reference and api I think the only way to progress is to get some help from
the developers directly or at least I hope to.
So coming to the issue:
The issue is that I don't manage to validate a form collection with the
collection constrain.
There two possibilities:
1.) Without Options (allowExtraFields, allowMissingFields, both disabled):
The form does not get submitted, I found following error accessing
$form->getErrors()
array(1) { [0]=> object(Symfony\Component\Form\
FormError)#744 (2) {
["messageTemplate":protected]=> string(41) "The fields {{ fields }}
were
not expected" ["messageParameters":protected]=> array(1) { ["{{ fields
}}"]=> string(3) ""0"" } } }
I don't understand this error than I defined every sub-entity-attribute...
2.) With Options (allowExtraFields, allowMissingFields, both enabled):
There is no validation and the form gets persisted even there are constrain
breaks
Here is the entity:
<?php
namespace PUS\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
*
@ORM\Entity(repositoryClass="PUS\AppBundle\Repository\CustomerRepository")
* @ORM\Table(name="pus_customers")
*/
class Customer
{
/**
* @ORM\Id()
* @ORM\Column(name="customer_id", type="integer")
* @ORM\GeneratedValue()
*/
private $customerId;
/**
* @Assert\Collection(
* fields = {
* "particular_id" = {
* @Assert\MaxLength(limit = 3)
* },
* "gender" = {
* @Assert\Choice(choices = {"m", "f"}, message = "Choose
a valid gender")
* },
* "title" = {
* @Assert\Choice(choices = {"Prof Dr.", "Dr.", null},
message = "Falscher Titel")
* },
* "first_name" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 30, message = "Ihr Vorname ist
zu lang"),
* @Assert\MinLength(limit = 3, message = "Ihr Vorname ist
zu kurz")
* },
* "last_name" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 30, message = "Ihr Nachname
ist zu lang"),
* @Assert\MinLength(limit = 3, message = "Ihr Nachname
ist zu kurz")
* },
* "birth" = {
* @Assert\NotBlank(),
* @Assert\Date(message = "Etwas stimmt mit dem
Geburtsdatum nicht")
* }
* }
* )
*
* @ORM\ManyToMany(targetEntity="CustomerParticular")
* @ORM\JoinTable(name="pus_customers_rel_customers_particulars",
* joinColumns={@ORM\JoinColumn(name="customer_id",
referencedColumnName="customer_id")},
*
inverseJoinColumns={@ORM\JoinColumn(name="particular_id",
referencedColumnName="particular_id", unique=true)}
* )
*/
private $particulars;
/**
* @Assert\Collection(
* fields = {
* "street" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 40, message = "Ihre
Stra\xc3\x9fe ist zu lang"),
* @Assert\MinLength(limit = 8, message = "Ihr
Stra\xc3\x9fe ist zu kurz")
* },
* "streetNr" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 4, message = "Ihre
Stra\xc3\x9fennummer ist zu lang"),
* @Assert\MinLength(limit = 1, message = "Ihre
Stra\xc3\x9fennummer ist zu kurz")
* },
* "zipCode" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 5, message = "Ihre
Postleitzahl ist zu lang"),
* @Assert\MinLength(limit = 5, message = "Ihre
Postleitzahl ist zu kurz")
* },
* "city" = {
* @Assert\NotBlank()
* },
* "country" = {
* @Assert\NotBlank()
* }
* },
* allowMissingFields = true,
* allowExtraFields = true
* )
*
* @ORM\ManyToMany(targetEntity="CustomerAddress")
* @ORM\JoinTable(name="pus_customers_rel_customers_addresses",
* joinColumns={@ORM\JoinColumn(name="customer_id",
referencedColumnName="customer_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="address_id",
referencedColumnName="address_id", unique=true)}
* )
*/
private $addresses;
/**
* @Assert\Collection(
* fields = {
* "phoneNumber" = {
* @Assert\NotBlank(),
* @Assert\MaxLength(limit = 30, message = "Ihre
Telefonnummer ist zu lang"),
* @Assert\MinLength(limit = 6, message = "Ihr
Telefonnummer ist zu kurz")
* },
* "phoneType" = {
* @Assert\NotBlank(),
* @Assert\Choice(choices = {"Telefon Privat", "Telefon
Gesch\xc3\xa4ftlich", "Mobile Privat", "Mobile Gesch\xc3\xa4ftlich", "Fax
Privat"
, "Fax Gesch\xc3\xa4ftlich"}, message = "W\xc3\xa4hlen Sie einen
Telefontyp")
* }
* },
* allowMissingFields = true,
* allowExtraFields = true
* )
*
* @ORM\ManyToMany(targetEntity="CustomerPhone")
* @ORM\JoinTable(name="pus_customers_rel_customers_phones",
* joinColumns={@ORM\JoinColumn(name="customer_id",
referencedColumnName="customer_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="phone_id",
referencedColumnName="phone_id")}
* )
*/
private $phones;
/**
* @Assert\Collection(
* fields = {
* "emailAddress" = {
* @Assert\NotBlank(),
* @Assert\Email(message = "Ihre Email-Addresse stimmt
nicht")
* },
* "emailTypeType" = {
* @Assert\NotBlank(),
* @Assert\Choice(choices = {"Privat",
"Gesch\xc3\xa4ftlich"}, message = "W\xc3\xa4hlen Sie einen Telefontyp")
* }
* },
* allowMissingFields = true,
* allowExtraFields = true
* )
*
* @ORM\ManyToMany(targetEntity="CustomerEmail")
* @ORM\JoinTable(name="pus_customers_rel_customers_emails",
* joinColumns={@ORM\JoinColumn(name="customer_id",
referencedColumnName="customer_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="email_id",
referencedColumnName="email_id")}
* )
*/
private $emails;
public function __construct() {
$this->particulars = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->phones = new ArrayCollection();
$this->emails = new ArrayCollection();
}
// getters and setters
Thank you for the good work and solutions for the world!
Best Regards,
Bodo Kaiser
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en