cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Column name containing parentheses causes errors

Open SoccerField24x7 opened this issue 11 years ago • 5 comments

I have a column named: billtime(rounded) which is legal in MySQL. How can this be represented in the Phalcon model?

/**
 *
 * @var string
 */
public $billtime(rounded);

Leaving it as is, causes errors to be thrown.

SoccerField24x7 avatar Sep 25 '15 02:09 SoccerField24x7

php does not support brackets in variable names. http://php.net/manual/en/language.variables.basics.php

Green-Cat avatar Sep 25 '15 08:09 Green-Cat

You could try independent column mapping: https://docs.phalconphp.com/en/latest/reference/models.html#independent-column-mapping

public $billtime_rounded;
public $etc;

public function columnMap()
{
    return array(
        'billtime(rounded)' => 'billtime_rounded',
        'etc' => 'etc',
    );
}

VCJeroen avatar Sep 25 '15 13:09 VCJeroen

Right @Green-Cat, PHP does not support it, which is why it is a bug that the dev tools create it that way, and the reason for my inquiry as to how the Phalcon team expects people to handle it. Thank you for your work around @VCJeroen! Presumably you have to define every column in the model though. In this particular case, this table has 30+ columns. Not impossible to do, but a pain to specify each of them individually.

SoccerField24x7 avatar Sep 25 '15 14:09 SoccerField24x7

@SoccerField24x7 please follow the advice of @VCJeroen

andresgutierrez avatar Sep 25 '15 14:09 andresgutierrez

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Apr 17 '18 04:04 stale[bot]