Filter based on contained model with paginate

Hi!

I try to filter the paginated model with assiocated data. Unfortanely I get a unknown column error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘Amenities.amenity_id’ in ‘where clause’

I have tried to add sort whitelist but does not work either. The code:

        if($this->request->getQuery('amenity') !== NULL && $this->request->getQuery('amenity') !== "")
        {
            foreach($this->request->getQuery('amenity') as $amenity)
            {
                $where[] = ['Amenities.amenity_id' => $amenity];
            }
        }

        $this->paginate = [
            'contain' => array(
                'Amenities',
                'Images'
            ),
        ];

        $listings = $this->paginate($this->Listings->find('all')->where([$where]));

What Am i doing wrong :)?

Thanks, Mark

You want to do filtering by associated data?