The Space

28/05/2008  |  Publié dans cakephp, tips

Last week-end, I came accross a tiny but annoying problem.

I had this simple line of code :

$artist = $this->Artist->find(array(’name’ => $name);

Most of the times, it worked fine. But sometimes I had to search for “!!!” or “In Scary Stereo” and CakePHP threw an error, saying the SQL query was wrong. And it was, because CakePHP automagically transformed the “!” and the “In” into SQL operators…
I first thought that I need to force the “equal” operator, like this:

$artist = $this->Artist->find(array(’name’ => ‘=’. $name);

Then someone on CakePHP’s google group gave me that tip :

$artist = $this->Artist->find(array(’name’ => ‘!-’.$name);

It didn’t work. But Grant Cox suggested me to add as simple space after the equal sign:

$artist = $this->Artist->find(array(’name’ => ‘= ‘. $name);

That worked!!

Too much magic kills the magic…

[edit]
La RC1 change quelque peu tout cela : l’opérateur passe à gauche de la flèche, et c’est bien mieux ainsi. En revanche, j’ai un gros soucis de connexion à deux bases de données différentes avec cette nouvelle version.

Archives

Liens au pif

  • blogcatalog
  • Mark Story
  • snook.ca
  • photos de bubu
  • Cakebaker
  • Frédéric de Villamil
  • Formation CakePHP
  • Google Group CakePHP Fr
  • Le blog de Pierre
  • pictures of the north country
  • POPnews
  • Chez Trân
  • Debuggable
  • mes photos
  • Communauté française CakePHP
  • Derniers commentaires

    • Pierre MARTIN: Tu peux essayer de rajouter un champ “counterCache” dans ton modèle....
    • rafaelbandeira3: hey, thanks for the reference of my work! btw, may I ask you to correct my name?...
    • Michael: Salut ! Ayant lu les 2 premiers, il semble évident de recommander aux éventuels...
    • Michael: Article sympa, mais j’y ajouterai 2 ouvrages : http://www.apress.com/book/...
    • Xavier: Bonjour, Merci pour cette critique. Nous comptons mettre à jour le livre blanc assez...
  • Derniers trackbacks