Fix EZP-20943: Regression caused by op_code removal

This PR resolves issue https://jira.ez.no/browse/EZP-20943.

Double `AND` in DB query is fixed and basic unit test added.