How to apply some validations in a column in Propel schema?

102 Views Asked by At

I am using Propel schema to create database tables. In a table, i need to create a 'name' column which should hold a 'short string', 'all in lower case', and 'with no spaces', for example: 'join', 'appointment'.

How can I define this column in schema.xml with given constraints? Or do I have to create a custom validator to get it done?

1

There are 1 best solutions below

0
Qiniso On

You can define a validate behaviour in your schema.xml.

There are several validators to choose from, you would probably use the Choice Validator.

Example:

<table name='TableName'>
  ...
  <column name='name' type='varchar' size='20' />
  <behavior name="validate">
    <parameter name="rule1" value="{column: name, validator: Choice, options: {message: Please enter a valid name }}" />
  </behavior>
</table>