[symfony-users] Re: sfValidatorPropelUnique with sfValidatorPropelChoiceMany

2010-02-22 Thread Tomasz Ignatiuk
This solution works

public function configure()
  {
  // (...)
  $this-validatorSchema-setPostValidator(
  new sfValidatorCallback(array(
  'callback' = array($this, 'checkUniqueness'),
  'arguments' = array(
'model' = 'ProduktPartner',
'multiple_column' = 'language_logo',
'columns' = array('partner_logo', 'product_logo',
'language_logo')
;
  }

  public function checkUniqueness($validator, $values, $aArguments)
  {
foreach ($values[$aArguments['multiple_column']] as $one_of_many)
{
  $criteria = new Criteria();

  foreach ($aArguments['columns'] as $column)
  {
$colName =
call_user_func(array(constant($aArguments['model'].'::PEER'),
'translateFieldName'), $column, BasePeer::TYPE_FIELDNAME,
BasePeer::TYPE_COLNAME);
if($column != $aArguments['multiple_column'])
  $criteria-add($colName, $values[$column]);
else
  $criteria-add($colName, $one_of_many);
  }

  $object =
call_user_func(array(constant($aArguments['model'].'::PEER'),
'doSelectOne'), $criteria);


  if(is_object($object))
  {
  $error = new sfValidatorError($validator, sprintf('An object
with the same %s %s already exist.', $aArguments['multiple_column'],
$one_of_many));
  throw new sfValidatorErrorSchema($validator, array('' =
$error));
  }
 }
 return $values;
  }

-- 
You received this message because you are subscribed to the Google Groups 
symfony users group.
To post to this group, send email to symfony-us...@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.



[symfony-users] Re: sfValidatorPropelUnique with sfValidatorPropelChoiceMany

2010-02-16 Thread Massimiliano Arione
Override sfValidatorPropelUnique and define a method isUpdate() that
return always false

On 15 Feb, 15:54, Tomasz Ignatiuk tomek.ignat...@gmail.com wrote:
 Hi

 I have a table with unique index of 3 columns. So I use this:

     $this-validatorSchema-setPostValidator(
       new sfValidatorPropelUnique(array('model' = 'ProduktPartner',
 'column' = array('partner', 'product', 'language')))
     );

 It works well.
 But I would like to make some changes in the form. To give a
 possibility to choose one partner, one product and many languages. I
 have changed processForm to save for each language different object
 with the same partner and product. But then, sfValidatorPropelUnique
 doesn't work. Any ideas how to solve this problem out?

-- 
You received this message because you are subscribed to the Google Groups 
symfony users group.
To post to this group, send email to symfony-us...@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.



[symfony-users] Re: sfValidatorPropelUnique with sfValidatorPropelChoiceMany

2010-02-16 Thread Tomasz Ignatiuk
Unfortunatelly in doesn't help. Still validator passes and Propel
Exception occurs (There is already object with same partner,product
and language).

-- 
You received this message because you are subscribed to the Google Groups 
symfony users group.
To post to this group, send email to symfony-us...@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.