How do I query for all users that bought a license? I’m trying to use Craft Commerce with the Digital Products plugin for a site where users can pay for being listed on that site.

Therefore I need to query for all users with certain criterias plus a valid license.

I’m not sure how to tackle this. I tried something like this, but it doesn’t work.

{% for user in craft.users({
    group: 'profiles',
    relatedTo: craft.digitalProducts.products({type: 'access'})
}) %}


Another approach would be to list all licenses, collect the related users and then list them. But that doesn’t seem like a good idea either, in terms of performance.

Any hint is much appreciated.
I don't think it's currently possible in as clean as manner as you'd like. I'd tackle the problem by writing a small plugin that queries the database and returns a list of user ids that match the criteria.

Remember, though, is that a license does not necessarily have a user id attached to it - a license must have either a user id or an email assigned to, so you might want to keep that in mind.