We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How would this select in Phalcon ?. How a function or using model or something else?

Hi, I use this code to generate my next PRIMARY code with PURE PHP , as might write in Phalcon, If possible with model

$prefijo ="CLI, TRA, PRO" ONLY 3 letter or IF you analyze the code can change to more
$table = Table to where it will generate the code
$campoPrimario = Field this table as the primary key or you want to generate you the code

$prefijo="CLI"

select ('$prefijo' || (case when max($campoPrimario)  IS NULL THEN '0000000001' ELSE LPAD((SUBSTRING(max($campoPrimario), 4) + 1), 10, '0') END)) AS codigo
from $tabla

RESULT="CLI0000000001"

CONSULTATION IS MADE FOR ORACLE DATABASE COMMAND LPDAD ADVANTAGE TO DIVIDE THE CHAIN AS A LEFT OR RIGHT IN EXCEL

I prefer to use modelsManager. You can do case in it.



81.1k

And as would using ModelManager