Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saving a model with empty (not null) values fails when column is defined "not Null" #3035

Closed
swen100 opened this issue Nov 14, 2014 · 2 comments

Comments

@swen100
Copy link

swen100 commented Nov 14, 2014

i tried to create an entry in a MySQL-Database. My model/table has a column which is defined not null. For MySQL (maybe for other RDMS also) an empty string is not null, so it can be used within insertions. But Phalcon misinterpretes it. Phalcon thinks that it is not valid. That is wrong.

My System is:
Phalcon Version 1.3.4
PHP 5.5
MySQL 5.6

CREATE TABLE `dummy` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(80) NOT NULL,
   PRIMARY KEY (`id`)
);
// create object and set an empty (not null) value
$myModel = new dummy();
$myModel->name = '';

// show that 'name' is empty, but not null
echo "<pre>";
var_dump($myModel->toArray());
echo "</pre>";

// try to create (insert into table)
// and show errors if something was wrong
if( !$myModel->create() ) {
      echo "an error occured:<br>";
      foreach( $myModel->getMessages() as $message ) {
           $this->flash->error((string) $message);
      }
}

result:

array(2) {
  ["id"]=>
  NULL
  ["name"]=>
  string(0) ""
}

an error occured:
name is required

if i use straight sql like this:

INSERT INTO `dummy` (`id`, `name`) VALUES (Null, '');

all works fine.

The value i have set is empty, but it is not Null. With phalcon the creation of a new object fails. In my opinion it should not fail, but it does...

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@swen100 swen100 changed the title create model with empty (not null) values fails when column is defined "not Null" saving a model with empty (not null) values set fails when column is defined "not Null" Nov 14, 2014
@swen100 swen100 changed the title saving a model with empty (not null) values set fails when column is defined "not Null" saving a model with empty (not null) values fails when column is defined "not Null" Nov 14, 2014
@swen100
Copy link
Author

swen100 commented Nov 19, 2014

i now saw that it references an old "problem" #440

@andresgutierrez
Copy link
Contributor

This is fixed in 2.0.3 #440 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants