# Rule isUnique and allowMultipleNulls

**URL:** <https://discourse.cakephp.org/t/rule-isunique-and-allowmultiplenulls/9004>\
**Category:** Need Help\
**Created:** [February 12, 2021, 9:01am UTC](https://discourse.cakephp.org/t/rule-isunique-and-allowmultiplenulls/9004 "2021-02-12T09:01:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExtraPaul](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/extrapaul/32/2037_2.png) [@ExtraPaul](https://discourse.cakephp.org/u/ExtraPaul)\
**Post date:** [February 12, 2021, 9:01am UTC](https://discourse.cakephp.org/t/rule-isunique-and-allowmultiplenulls/9004/1 "2021-02-12T09:01:22Z")

</div>

Hello;

In my table Nomenclatures, the column “hos” can be null, but must be unique.  
Thus I add a rule in NomenclaturesTable.php :

```
public function buildRules(RulesChecker $rules): RulesChecker
    {
        $rules->add($rules->isUnique(
            ['hos'], 
            ['allowMultipleNulls'=>true]
        ));
        return $rules;
    }

```

This option [is documented here](https://book.cakephp.org/4/en/orm/validation.html#creating-unique-field-rules).  
But it does not work as expected : by sending the field with no value, I get the field with a red border and the message “1”. By replacing [‘allowMultipleNulls’=\>true] by [‘allowMultipleNulls’=\>“TOTO”] for example, I get the error message “TOTO”.  
This option runs as a message !

Even stranger…  
In the documentation, in the [Creating re-usable rules chapter](https://book.cakephp.org/4/en/orm/validation.html#creating-custom-re-usable-rules), a class IsUniqueWithNulls is referenced.  
I don’t find any documentation about this class, and the example does not work in my code !

What is the solution ?  
Thanks.
