Development

#1286 (Admin-generator: addSortCriteria case sensitive problem)

You must first sign up to be able to contribute.

Ticket #1286 (closed defect: fixed)

Opened 2 years ago

Last modified 5 days ago

Admin-generator: addSortCriteria case sensitive problem

Reported by: noel Assigned to: fabien
Priority: major Milestone: 1.1.0
Component: generator Version: 1.1.0 RC2
Keywords: Cc:
Qualification: Ready for core team

Description

When you create a model with upper case columns, the generated method addSortCriteria throws an propel exception because the column to sort is not found.

This exception is thrown by the xxxPeer::translateFieldName method, because $sort_column is in lower case, and it should be in upper case.

protected function addSortCriteria ($c)
  {
    if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/utilisateur/sort'))
    {
      $sort_column = UtilisateurPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);

An extract of a peer class :

<?php
private static $fieldKeys = array (
        BasePeer::TYPE_PHPNAME => array ('UtId' => 0, 'Nom' => 1, 'Prenom' => 2 ),
        BasePeer::TYPE_COLNAME => array (UtilisateurPeer::UT_ID => 0, UtilisateurPeer::NOM => 1, UtilisateurPeer::PRENOM => 2),
        BasePeer::TYPE_FIELDNAME => array ('UT_ID' => 0, 'NOM' => 1, 'PRENOM' => 2 ),
        BasePeer::TYPE_NUM => array (0, 1, 2)
    );
[...]
static public function translateFieldName($name, $fromType, $toType)
    {
        $toNames = self::getFieldNames($toType);
        $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
        if ($key === null) {
            throw new PropelException("'$name' could not be found in the field names of type  '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
        }
        return $toNames[$key];
    }
?> 

Attachments

action.class.patch (1.1 kB) - added by noel on 01/04/07 13:09:25.

Change History

01/04/07 13:09:00 changed by noel

[PATCH] Compare with the BasePeer::PHPNAME instead of BasePeer::FIELDNAME

in data/generator/sfPropelAdmin/default/template/actions/actions.class.php :

//force column to lower case
$sort_column = strtolower($sort_column);
//camelize lower case to be able to compare with BasePeer::TYPE_PHPNAME
$sort_column = sfInflector::camelize($sort_column);
//translate field name
$sort_column = <?php echo $this->getClassName() ?>Peer::translateFieldName($sort_column, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);

01/04/07 13:09:25 changed by noel

  • attachment action.class.patch added.

01/05/07 08:49:22 changed by fabien

  • status changed from new to closed.
  • resolution set to invalid.

You must use field names in your generator.yml file, not php names.

01/05/07 10:01:58 changed by noel

  • status changed from closed to reopened.
  • resolution deleted.

Hello fabien,

I'm not using php names in my generator.yml, just field names in lower case, instead in lower case. I have the same error when I click on a header of column to sort the list.

In my model, like I've describe on this tickets, the table column are in upper case, so in BasePeer::FIELDNAME, the value are also in upper case. Then, when you sort your list, ie with the column header of the list, you ask backend.php/utilisateur/list/sort/nom/type/asc , and the translateFieldName method return null because there is no column named "nom".

Then I transform the sort parameter by a camelized one, which can be compare with its php name.

See this thread for more information: http://www.symfony-project.com/forum/index.php?t=rview&goto=18828

01/31/07 20:35:03 changed by subzero2000

  • priority changed from critical to major.

Updated ticket to reflect the fact that critical is no longer an available priority.

02/21/07 14:45:44 changed by francois

  • version deleted.
  • component set to generator.

03/29/07 09:29:51 changed by Markus.Wagner

I am successfully using the patch.

I have 2 situation, where I need the patch:

*) with Oracle database, because all columnames are uppercase character *) with mySQL if I use columnnames with uppercase character

08/29/07 10:31:08 changed by gregoire

  • milestone set to 1.0.8.

08/29/07 10:31:35 changed by gregoire

  • owner set to gregoire.
  • status changed from reopened to new.

08/30/07 14:10:35 changed by gregoire

  • owner changed from gregoire to fabien.
  • milestone changed from 1.0.8 to 1.1.0.

We did consider fixing it in the 1.0 branch, but fixing it would break backward 1.0 compatibility.

09/08/07 16:58:33 changed by FabianLange

  • qualification set to Ready for core team.

01/31/08 20:22:49 changed by Leon.van.der.Ree

I don't see why this patch would break backward compatibility, but thanks for the patch I now use it in the sfExtjsThemePlugin

06/23/08 04:04:50 changed by dwhittle

  • version set to 1.1.0 RC2.
  • milestone changed from 1.1.0 to 1.1.0 FINAL.

This should be fixed in 1.1, I have committed in sfPropelPlugin in r9619.

06/27/08 00:36:37 changed by dwhittle

This is resolved in dwhittle branch in r9908. Should I merged for 1.1-Final?

06/27/08 14:25:54 changed by noel

  • status changed from new to closed.
  • resolution set to fixed.

(In [9926]) 1.1: fixed addSortCriteria case sensitive problem (closes #1286)

06/29/08 23:38:42 changed by FabianLange

  • milestone changed from 1.1.0 FINAL to 1.1.0.