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

Unable to save empty string (not null) - phalcon says value is required #646

Closed
alvassin opened this issue May 17, 2013 · 3 comments
Closed

Comments

@alvassin
Copy link

How i am able to save just empty string to mysql varchar field, that is not allowed to be null? i can't change database fields, and i don't want to write hardcode. I can't skip it, because many actions in my project requires this field in a model. E.g.:

$model->field = ''; // empty string is a value.
$model->save(); // error
@nikolasha
Copy link

$model->field = new \Phalcon\Db\RawValue('""');
$model->save();

see here

@alvassin
Copy link
Author

@nikolasha Thank you very much for you link to previous same post.

About this solution - it is really funny. Whos sick brain did came up with this idea? I remembered question from stackoverflow "How it is better to calculate sum of two numbers?" and the most popular (and it was marked as correct) answer was "Use query plugins, [some plugins list, where you need to create object to each number and operator]. Only noobies and idiots calculate sum without objects". Ok. Lets create objects for each empty string value. Nice solution.

I will try some ways to re-implement validation, as phalcon said in previous post. Thank you.

But - from my point of view - this logic is VERY strange. A comment for @phalcon - i will leave it here, because previous topic (linked to current) is closed. If you get empty data in models and if you save it - it is ok. You need to implement (or specify) validators, to prohibit it. Currently logic is non-usable, and very hard to understand.

P.S. Perhaps my last message is not polite. Please, take it easy, it is painful to watch how your favourite framework implement more and more strange solutions.

@phalcon
Copy link
Collaborator

phalcon commented May 20, 2013

Keeping the discussion in #440

@phalcon phalcon closed this as completed May 20, 2013
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