notorm
notorm copied to clipboard
query for columns that are not null
What would be a good way to query for a column that IS NOT NULL? From reading the code I can see no way to do that.
While waiting for an answer I will prepare a PR how I would do it.
Cheers! :-)
Hi,
Did you tried $db->table()->where('column_name IS NOT NULL')
?
That actually seems to work, judging from the tests. I'm not entirely sure, why, though ...
Since the code I have to maintain works very extensively with arrays, I would like to explicitly add where("column", "is not null") ... what do you think?
How then you distinct when column contains string "IS NOT NULL"
and column literally IS NOT NULL
?
That's a good point you make there. Intuitively I would answer that with $table->where($col, "'IS NOT NULL'");
but it's not really ideal considering backwards compatibility ... do you have a suggestion using the array syntax?
Just a quick thought: $db->table()->where($col, new IsNotNull())
. Then at the place where
is implemented check its second argument for instanceof IsNotNull
.
Hi,
This might work:
$db->table()->where("NOT $column", null);
On Tue, Oct 20, 2015 at 8:29 PM, Vladimir Barbarosh < [email protected]> wrote:
Just a quick thought: $db->table()->where($col, new IsNotNull()). Then at the place where is implemented check its second argument for instanceof IsNotNull.
— Reply to this email directly or view it on GitHub https://github.com/vrana/notorm/issues/109#issuecomment-149657366.
Right from the docs. )
$table->where("NOT field", array("x", "y"))
Translated to NOT field IN ('x', 'y') (with automatic escaping)
So I guess it would be better to remove the new code in Result.php
and just add more tests.
I also think that the documentation could be enhanced in that regard. Is there a repository where I could do that, which I missed?