<p>You can set it to <code>':empty:'</code>, as mentioned in the <a href="https://github.com/craftcms/cms/blob/2.6.3000/src/helpers/DbHelper.php#L447" rel="nofollow noreferrer"><code>DbHelper::parseParam()</code></a> documentation.</p>

CC BY-SA 3.0
2017-12-12T09:22:23.767Z
2017-12-12T09:22:23.767Z
carlcs
<p>I'm trying to add a source on a custom element type that shows entries with an empty <code>assigned_user_id</code> field. This criteria is not honored and returns the same results as the "All Entries" source. Is there any way to specify a null or empty string criteria value?</p>

<pre><code>public function getSources($context = null)
{
    $sources = [
        '*' =&gt; [
            'label' =&gt; Craft::t('All Entries'),
            'defaultSort' =&gt; [
                'test_plugin.dateCreated',
                'desc'
            ]
        ]
    ];

    $sources[] = ['heading' =&gt; 'Assignments'];

    $sources['unassigned'] = [
        'label'    =&gt; Craft::t('Unassigned'),
        'criteria' =&gt; ['assigned_user_id' =&gt; '']
    ];

    return $sources;
}
</code></pre>

CC BY-SA 3.0
2017-12-12T04:59:21.410Z
Is your `assigned_user_id` a Craft relation or just a simple integer?
Robin Schambach
<plugin-development><elementtype><sources>
Custom ElementType empty getSource criteria?
# Custom ElementType empty getSource criteria?

(Asked by: username_0 on 2017-12-12)

I'm trying to add a source on a custom element type that shows entries with an empty assigned_user_id field. This criteria is not honored and returns the same results as the "All Entries" source. Is there any way to specify a null or empty string criteria value?
public function getSources($context = null)
{
    $sources = [
        '*' => [
            'label' => Craft::t('All Entries'),
            'defaultSort' => [
                'test_plugin.dateCreated',
                'desc'
            ]
        ]
    ];

    $sources[] = ['heading' => 'Assignments'];

    $sources['unassigned'] = [
        'label'    => Craft::t('Unassigned'),
        'criteria' => ['assigned_user_id' => '']
    ];

    return $sources;
}

**Tags:** plugin-development, elementtype, sources

> **Comments:**
> **username_1**: Is your `assigned_user_id` a Craft relation or just a simple integer?  

---

## 1 answers

### Answer by username_2 on 2017-12-12. Score: 1 | Accepted answer

You can set it to `':empty:'`, as mentioned in the [`DbHelper::parseParam()`](https://github.com/craftcms/cms/blob/2.6.3000/src/helpers/DbHelper.php#L447) documentation.


---

