Validator 'required="true"' doesn't work. #473

Closed
nusov opened this Issue Sep 24, 2012 · 2 comments

Comments

Projects
None yet
3 participants

nusov commented Sep 24, 2012

Hi,
I've created the schema with 'required="true"' attributes (from manual)..
but when i do

$item = new Item();
$item->save();

it saves with no errors!

<?xml version="1.0" encoding="UTF-8"?>
<database name="start" defaultIdMethod="native">
  <table name="book" phpName="Book">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
    <column name="title" type="varchar" size="255" required="true" />
    <column name="isbn" type="varchar" size="24" required="true" phpName="ISBN"/>
    <column name="publisher_id" type="integer" required="true"/>
    <column name="author_id" type="integer" required="true"/>
  </table>
</database>
    public function indexAction()
    {
        $book = new Book();
        $book->save();
    }

instead of any exception i get a row where fields filled with ''

I tried to debug SQL and propel produces SQL INSERT with just ID field
INSERT INTO book (ID) VALUES (NULL)

Hope this makes sense.

nusov commented Sep 24, 2012

BTW - $book->validate() returns true

Member

jaugustin commented Sep 24, 2012

required has nothing to do with the validator, but only tell MySQL to create a column NOT NULL.

For validator you need to add validator rules :

http://www.propelorm.org/documentation/05-validators.html

<column name="username" type="VARCHAR" size="25" required="true" />
<validator column="username">
  <rule name="required" message="Username is required." />
</validator>

@willdurand willdurand closed this Nov 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment