Schema::Room->search( { departments.deptid => { '!=', 1 }, -or => [ departments.dept => { '!=', 3 }, departments.dept => { '!=', 42 }, ], }, { join => ['departments'] group_by => 'departments.deptid', } );