2013-03-04 69 views
1

使用案例

我在學習Symfony2,並且正在創建一個乒乓球跟蹤應用程序來學習該框架。我已經配置我的實體如下。如何驗證同一個實體的兩個實例?

Player 1..n Result n..1 Match 

在我的表格中,我想驗證一場比賽的比分是否正確。

實施

MatchresultsArrayCollection()

我的MatchTypeResultType表單包含以下內容。

// Form\MatchType 
    $builder->add('matchType', 'entity', array(
      'class' => 'PingPongMatchesBundle:MatchType', 
      'property' => 'name', 
     ) 
    ) 
    ->add('results', 'collection', array(
      'type' => new ResultType(), 
      'allow_add' => true, 
      'by_reference' => false, 
     ) 
    ) 
    ->add('notes'); 

// Form\ResultType 
    $builder->add('player', 'entity', array(
       'class' => 'PingPongPlayerBundle:Player', 
       'query_builder' => function(EntityRepository $er) { 
        return $er->createQueryBuilder('p') 
         ->orderBy('p.firstName', 'ASC'); 
       }, 
      )) 
      ->add('score'); 

問題

我需要能夠驗證分數。不過,我不知道如何處理這種類型的驗證,因爲我需要比較我的Result#score的兩個實例,以瞭解它們是否有效。

是否有人能夠建議我可以使用的方法或方法,以便能夠比較Result#score這兩個不同的實例?例如,我可以驗證Match實體中的ArrayCollection嗎?

回答

相關問題