Jasper Tey Mon Jan 31 04:10:34 -0500 2011

Subject: validates_uniqueness_of does not account for nulls?

I noticed when I have a validation as such:

static $validates_uniqueness_of = array (
    array (
        array (

The validation does not account for null values. In other words, if there already exists a record with the (col_a, col_b) values ("apple", NULL), the validation does not stop another ("apple",NULL) record from being saved. I suspect this has something to do with the fact that when checking for nulls in a select statement, the where clause is

where col_b is NULL

as opposed to the usual
where col_b = 'some value'

So, my current workaround is to do my own validation via the model's validate() function.

This brings up another point; phpactiverecord does not translate nulls on the php side into nulls on the mysql end, does it?

Kien La Fri Feb 04 17:43:42 -0500 2011

I think you might be right. I've created a ticket for this https://github.com/kla/php-activerecord/issues/issue/121

It should be translating nulls from php into mysql correctly. If it isn't please provide an example for me to look at.


Yoan B Wed Mar 23 09:34:08 -0400 2011

Hi, I did a fix of that regard in one of my branches: https://github.com/greut/php-activerecord/compare/gh121

Feel free to improve the test if you can.