# beforeFind where datetime is null

**URL:** <https://discourse.cakephp.org/t/beforefind-where-datetime-is-null/5366>\
**Category:** Need Help\
**Created:** [December 6, 2018, 10:18am UTC](https://discourse.cakephp.org/t/beforefind-where-datetime-is-null/5366 "2018-12-06T10:18:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivero](https://avatars.discourse-cdn.com/v4/letter/o/a4c791/32.png) [@olivero](https://discourse.cakephp.org/u/olivero)\
**Post date:** [December 6, 2018, 10:18am UTC](https://discourse.cakephp.org/t/beforefind-where-datetime-is-null/5366/1 "2018-12-06T10:18:10Z")

</div>

Hi  
I have a brands and a users table and a join table brands\_users. The brands\_users table has an additional column “removed” (DATETIME).  
In the Users controller I have this function:

> public function view()  
> {  
> $this-\>Crud-\>on(‘beforeFind’, function (Event $event) {  
> $user = $this-\>Auth-\>identify();  
> $event-\>subject-\>query = $this-\>Users-\>find()-\>where([‘id’ =\> $user[‘id’] ]);  
> $event-\>getSubject()-\>query-\>contain([  
> ‘Brands’,  
> ‘Models’  
> ]);
> 
> });  
> return $this-\>Crud-\>execute();  
> }

This works but I would like to get only the Brands which don’t have a value in the “removed” column (in the brands\_users table).

I tired to implement a beforeFind in the BrandsUsersTable.php file but somehow it’s not working. Maybe it’s not the right approach at all? Or if it is, maybe someone can give me an example of a beforeFind function in a Table?

Thanks!

**UPDATE:**  
I figured it out. Below is a working beforeFind example (see the Type for $options). Also I had to include:

> use Cake\Event\EventListenerInterface;  
> use Cake\Event\Event;

```
public function beforeFind(Event $event, Query $query, \ArrayObject $options, $primary)    
{
    //Log::write('debug', $query);
    $query->where(['removed IS' => null]); 
}

```
