In brief, I have a table Tip, which has a FK pointing to TipAction.id The relation is correctly setup by Gii. However, the FK column in Tip can be set to NULL as the Action field is not compulsory.
That worked correctly! (with double quotes after the ? sign) I had tried something like that - only the comparison part and the operators were outside the quotes, which resulted in error.
However, I am going to enforce the required condition and create an additional entry in the Action table for this situation. The reason - I cannot filter display the NULL ones only as passing an empty value to search() clears out the filters.
Yes, the double quotes are needed there (typing error)…
For the filtering…
you can always use here some special symbol instead of ""… or for example "null" or "empty"
and for the filtering to work… when the user enter that text you are showing in the table as null… in the $model->search() method just check if the value is equal to that text… and in that case add a search criteria for null value instead of the entered text…
Hi, took a week to come back to this - was rushed with the project In that particular case, I rammed through the idea of compulsorily selecting an action type.
This idea is useful in other cases where I do have null values; which I am going to encounter soon.
So far, picking from Yii’s own strings, ‘Not set’ corresponds to null. In model’s search(),
Of course, I need to have this populated in the dropdown filter too - I will have to use some of CHtml’s functions to add “Not Set” in the filter values along with the Action model’s values. I will cross that bridge when I come to it.
So, putting this together with what’s been said above, if you have a related table that might have be null, and you want be able to filter on ALL values or on the ‘Not Set’ ones you can use something like: