Coder Social home page Coder Social logo

Comments (6)

scrnjakovic avatar scrnjakovic commented on May 31, 2024

Actually, this is more NFR as this is obviously due to the fact that all POST/GET values are strings, with the exception of array of course.

What I propose we do is have Form::bind turn empty strings into null by default before assigning it to the model. For those who, for whatever reason, want empty strings in their databases, they can allow it with something like

$form->allowEmptyStrings(
    [
        'fieldName'
    ]
);

or

$field = new Text(
    'field',
    [
        'allowEmptyString' => true
    ]
);

from phalcon.

niden avatar niden commented on May 31, 2024

@scrnjakovic Looking at this I have one concern. How would Phalcon know that an empty string is indeed an empty string vs. a null? There will be instances where the POST will be an empty string and this would be what I might want to add in the database vs a null.

Thoughs?

from phalcon.

scrnjakovic avatar scrnjakovic commented on May 31, 2024

@niden Without getting into a discussion on why would one want empty strings in a database, I suppose there is a valid use case somewhere, I still think those cases are quite rare or at least less common than having nullable column for when there is no value. So my idea was to treat all empty strings as nulls unless field is explicitly flagged to accept empty strings.

from phalcon.

zsilbi avatar zsilbi commented on May 31, 2024

I am not a fan of storing empty strings either, but reasonable use cases max exist.
It's not an example I'd use personally, but in view you could decide to print the stored content if it's a string (even if it's empty), or use an alternative method to gather the content when it's null.

Filters can be used on Form elements, so I'd maybe write a Filter which returns null if the input is empty then set it to the elements I need.
If it's required on all the elements I'd override Form::add() in the Form object.

from phalcon.

niden avatar niden commented on May 31, 2024

@zsilbi I like this approach better because it extends the forms even more for developers.

We already have Validators for forms (valid/not valid). We can also attach Filters or Transformers or Decorators so that we can achieve this transformation

I will move this to the 4.1 release because this requires significant work.

from phalcon.

scrnjakovic avatar scrnjakovic commented on May 31, 2024

Yeah, I don't mind that approach, I just advocate NULL being default and empty string optional. That makes more sense to me.

from phalcon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.