<p dir="auto">Hi to all :)</p>
<p dir="auto">I'm using Symfony 2.7 and I have a trouble with the Validator component.<br>
I wrote a configuration yaml and php code to validate a Test model:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Acme\Bundle\AcmeBundle\Model\Test:
    properties:
        message:
            - Type:
                type: string
                message: 'The message must be a string.'
            - Length:
                max: 10
                maxMessage: 'The message cannot be longer than {{ limit }} characters'"><pre class="notranslate"><span class="pl-ent">Acme\Bundle\AcmeBundle\Model\Test</span>:
    <span class="pl-ent">properties</span>:
        <span class="pl-ent">message</span>:
            - <span class="pl-ent">Type</span>:
                <span class="pl-ent">type</span>: <span class="pl-s">string</span>
                <span class="pl-ent">message</span>: <span class="pl-s"><span class="pl-pds">'</span>The message must be a string.<span class="pl-pds">'</span></span>
            - <span class="pl-ent">Length</span>:
                <span class="pl-ent">max</span>: <span class="pl-c1">10</span>
                <span class="pl-ent">maxMessage</span>: <span class="pl-s"><span class="pl-pds">'</span>The message cannot be longer than {{ limit }} characters<span class="pl-pds">'</span></span></pre></div>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$validator = $this-&gt;get('validator');

$model = new \Acme\Bundle\AcmeBundle\Model\Test();
$model
    -&gt;setMessage('aaaaaaaaaaaaaaaaaaaa');

$errors = $validator-&gt;validate($model);

if ($errors-&gt;count() &gt; 0)
{
    echo 'Errors num: '. $errors-&gt;count(). &quot;\n&quot;;
    $errorMessages = array();

    foreach ($errors as $error) 
    {
        $field = $error-&gt;getPropertyPath();

        if (!isset($errorMessages[$field]))
            $errorMessages[$field] = [];

        $errorMessages[$field][] = $error-&gt;getMessage();
    }

    var_dump($errorMessages);
}"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>validator</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get</span>(<span class="pl-s">'validator'</span>);

<span class="pl-s1"><span class="pl-c1">$</span>model</span> = <span class="pl-k">new</span> \<span class="pl-v">Acme</span>\<span class="pl-v">Bundle</span>\<span class="pl-v">AcmeBundle</span>\<span class="pl-v">Model</span>\<span class="pl-v">Test</span>();
<span class="pl-s1"><span class="pl-c1">$</span>model</span>
    -&gt;<span class="pl-en">setMessage</span>(<span class="pl-s">'aaaaaaaaaaaaaaaaaaaa'</span>);

<span class="pl-s1"><span class="pl-c1">$</span>errors</span> = <span class="pl-s1"><span class="pl-c1">$</span>validator</span>-&gt;<span class="pl-en">validate</span>(<span class="pl-s1"><span class="pl-c1">$</span>model</span>);

<span class="pl-k">if</span> (<span class="pl-s1"><span class="pl-c1">$</span>errors</span>-&gt;<span class="pl-en">count</span>() &gt; <span class="pl-c1">0</span>)
{
    <span class="pl-k">echo</span> <span class="pl-s">'Errors num: '</span>. <span class="pl-s1"><span class="pl-c1">$</span>errors</span>-&gt;<span class="pl-en">count</span>(). "\n";
    <span class="pl-s1"><span class="pl-c1">$</span>errorMessages</span> = <span class="pl-en">array</span>();

    <span class="pl-k">foreach</span> (<span class="pl-s1"><span class="pl-c1">$</span>errors</span> <span class="pl-k">as</span> <span class="pl-s1"><span class="pl-c1">$</span>error</span>) 
    {
        <span class="pl-s1"><span class="pl-c1">$</span>field</span> = <span class="pl-s1"><span class="pl-c1">$</span>error</span>-&gt;<span class="pl-en">getPropertyPath</span>();

        <span class="pl-k">if</span> (!isset(<span class="pl-s1"><span class="pl-c1">$</span>errorMessages</span>[<span class="pl-s1"><span class="pl-c1">$</span>field</span>]))
            <span class="pl-s1"><span class="pl-c1">$</span>errorMessages</span>[<span class="pl-s1"><span class="pl-c1">$</span>field</span>] = [];

        <span class="pl-s1"><span class="pl-c1">$</span>errorMessages</span>[<span class="pl-s1"><span class="pl-c1">$</span>field</span>][] = <span class="pl-s1"><span class="pl-c1">$</span>error</span>-&gt;<span class="pl-en">getMessage</span>();
    }

    var_dump(<span class="pl-s1"><span class="pl-c1">$</span>errorMessages</span>);
}</pre></div>
<p dir="auto">The output should show an error but I'm getting the same error message twice:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Errors num: 2
array(1) {
  [&quot;message&quot;]=&gt;
  array(2) {
    [0]=&gt;
    string(53) &quot;The message cannot be longer than 10 characters&quot;
    [1]=&gt;
    string(53) &quot;The message cannot be longer than 10 characters&quot;
  }
}"><pre class="notranslate"><code class="notranslate">Errors num: 2
array(1) {
  ["message"]=&gt;
  array(2) {
    [0]=&gt;
    string(53) "The message cannot be longer than 10 characters"
    [1]=&gt;
    string(53) "The message cannot be longer than 10 characters"
  }
}
</code></pre></div>
<p dir="auto">What am I doing wrong?</p>
<p dir="auto">I have a form with a collection of images. The user can re-order the images. I am using Doctrine2's Criteria for sorting the images.</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    public function getImages()
    {
        $criteria = Criteria::create()
            -&gt;orderBy(array('rank' =&gt; Criteria::ASC, 'id' =&gt; Criteria::ASC));

        return $this-&gt;images-&gt;matching($criteria);
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">getImages</span>()
    {
        <span class="pl-s1"><span class="pl-c1">$</span>criteria</span> = <span class="pl-v">Criteria</span>::<span class="pl-en">create</span>()
            -&gt;<span class="pl-en">orderBy</span>(<span class="pl-en">array</span>(<span class="pl-s">'rank'</span> =&gt; <span class="pl-v">Criteria</span>::<span class="pl-c1">ASC</span>, <span class="pl-s">'id'</span> =&gt; <span class="pl-v">Criteria</span>::<span class="pl-c1">ASC</span>));

        <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">images</span>-&gt;<span class="pl-en">matching</span>(<span class="pl-s1"><span class="pl-c1">$</span>criteria</span>);
    }</pre></div>
<p dir="auto">If the form is submitted and contains an error, the images are not loaded in the order submitted by the user. FYI, I am sorting the rank as a hidden field. The user drag/drops which updates the hidden rank in the html.</p>
<p dir="auto">I am pretty sure this was working correctly when I found it here: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="15784075" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/8315" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/8315/hovercard" href="https://github.com/symfony/symfony/issues/8315">#8315</a></p>
<p dir="auto">The Criteria class should re-order the collection using logic, rather than a query since the query has already been run.</p>