Posts Tagged ‘Propel’

The sfValidatorPropelUnique in symfony

Nov
17

Today, I wanted to do a signup form but I wanted distinct email addresses to be recorded. After some googlisations, I’ve spotted two problems.

As my field was an email address I thought something like “damn easy, I just have to use something like this: ”

$this->validatorSchema['email_1'] = new sfValidatorAnd(array(
  1.     new sfValidatorEmail(); ,
  2.     new sfValidatorPropelUnique(array(
  3.             'model' => $this->getModelName(),
  4.             'column' => 'email_1'
  5.          ),
  6.          array(
  7.              'invalid' => 'This email address is already assigned to an account.',
  8.          )
  9.     )
  10. ));

Though, after few tries I had an error that I’ve never seen before, saying that it has to be used as a postValidator. Before I understood how to deal with that, I’ve figured out something: I should simply add in my schema

  1. index: unique

in my email field… Damn… But since I’m definitly 2 cool, here is the correct syntax to use in your UserForm.class.php (basically, it shouldn’t be used if you defined correctly your schema.yml though!) :

$this->validatorSchema->setPostValidator(
  1.             new sfValidatorPropelUnique(array(
  2.                 'model' => 'User',
  3.                 'column' => array('email_1')
  4.             ),
  5.             array(
  6.                 'invalid' => 'An account is already registered with this email address.',
  7.             )
  8.         ));

Once again, thanks symfony to allow us escaping from so much troubles !

Propel 1.4.0 stable has been released

Nov
8

The stable version of Propel 1.4.0 has been released today. The official annouce has been made on the new official Propel’s blog. You could find here:

You could also find in the official documentation what is new in Propel 1.4.

Yo, what’s up Propel 1.4 ?

Oct
13

Propel 1.4
Read more »

Propel: jointure avec plusieurs conditions

Feb
28

J’ai été très récemment confronté à un problème avec Propel au moment de faire une jointure: il me fallait faire la jointure sur 2 champs. Aussi, le fait d’être tombé sur une demande similaire il y’a quelques heures sur le Google Groupe symfony-fr m’a poussé à poster directement une solution ici.

Voici le cas qui nous servira d’exemple en SQL:

  1. SELECT * FROM user LEFT JOIN diplome ON (user.id_diplome = diplome.id_diplome AND user.version_diplome = diplome.version_diplome)

Comme vous pouvez le constater, rien de bien méchant en SQL. Toutefois, lorsqu’il s’agit de “convertir” cette requête en Propel, la tâche devient plus ardue puisque après avoir fait un tour sur le site officiel de Propel, ce cas ne semble pas être géré jusqu’à la version 1.3 incluse. Espérons que celà sera corrigé dans la 1.4.

Mais comme je suis (encore) un mec sympa, voici une petite technique pour arriver à ses fins:

  1. $c = new Criteria();
  2. $c->addJoin(DiplomePeer::ID_DIPLOME, UserPeer::ID_DIPLOME . ' AND ' . DiplomePeer::VERSION_DIPLOME . ' = ' . UserPeer::VERSION_DIPLOME, Criteria::LEFT_JOIN);
  3. $users = UserPeer::doSelect($c);

Voilà de quoi éviter de se cogner la tête contre les murs !