Hi, I'd strongly favor not doing such a "recursive" validation by default. When I create a form 99% of the time I only want to validate the data submitted in fact I can't even think of a case where I'd want to do a deeper validation right now. Checking the city when you only submit a user seems beyond the scope of what the validator should bother with.
Regards, Dennis On Sunday, April 17, 2011 10:36:43 AM UTC+2, Bernhard Schussek wrote: > > Hi Matt, > > The problem is that by default the data of each field is validated. For the > entity field this is the selected entity. Does it make sense to generally > disable validation for entity fields? > > Bernhard > > Am 16.04.2011 21:38 schrieb "Matt Johnston" <ma...@mjohnston.com>: > > I have two entities that are joined by a ManyToOne relation. Each > entity has it's own set of validators. When I submit a form for the > one object, the related object is also being validated. Is there any > way that the related object can not be validated? > > Here is an example, I am using Symfony2 PR11: > > class User { > ... > /** > * @orm:Column(type="string",nullable=false, unique=true) > * @assert:NotBlank() > */ > protected $name; > > /** > * @orm:ManyToOne(targetEntity="City") > * @orm:JoinColumn(name="city_id", > referencedColumnName="id",nullable=false) > * @assert:NotNull() > */ > protected $city; > > } > > class City { > ... > /** > * @orm:Column(type="string",nullable=false) > * @assert:NotBlank() > */ > protected $name; > > } > > In my UserForm configure() I add a reference to the City: > > $this->add(new EntityChoiceField('city', array( > 'em' => $em, > 'class' => 'MyBundle\Entity\City', > 'property' => 'name' > ))); > > The form displays correctly and creates a drop down list of all > existing cities pulled from the database. When I submit my UserForm > and validate it, I get errors that the city is missing a name. Why is > the validation propagating down to the related object? All the user object > needs to > know is if the city id is present and it doesn't need all the > additional fields for the city. > > -- > 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 users" group. > To post to this group, send email to symfon...@googlegroups.com > To unsubscribe from this group, send email to > symfony-user...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > > -- 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 users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en