Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to validate two instances of the same entity?
    primarykey
    data
    text
    <h1>Use case</h1> <p>I am learning Symfony2 and am creating a Table Tennis tracking app to learn the framework. I have configured my entities as follows. </p> <pre><code>Player 1..n Result n..1 Match </code></pre> <p>On my form I'd like to validate that the scores for a match are correct.</p> <h1>Implementation</h1> <p><code>Match</code> has an <code>ArrayCollection()</code> of <code>results</code>. </p> <p>My <code>MatchType</code> and <code>ResultType</code> forms contain the following.</p> <pre><code> // Form\MatchType $builder-&gt;add('matchType', 'entity', array( 'class' =&gt; 'PingPongMatchesBundle:MatchType', 'property' =&gt; 'name', ) ) -&gt;add('results', 'collection', array( 'type' =&gt; new ResultType(), 'allow_add' =&gt; true, 'by_reference' =&gt; false, ) ) -&gt;add('notes'); // Form\ResultType $builder-&gt;add('player', 'entity', array( 'class' =&gt; 'PingPongPlayerBundle:Player', 'query_builder' =&gt; function(EntityRepository $er) { return $er-&gt;createQueryBuilder('p') -&gt;orderBy('p.firstName', 'ASC'); }, )) -&gt;add('score'); </code></pre> <h1>Issue</h1> <p>I need to be able to validate the scores. However I'm not sure how to approach this type of validation as I need to compare two instances of my <code>Result#score</code> in order to know if they are valid or not. </p> <p>Is anyone able to suggest a method or approach that I could use in order to be able to compare <code>Result#score</code> between the two different instances? Can I validate the <code>ArrayCollection</code> in the <code>Match</code> entity for example?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload