1

私はgrailsが初めてで、パフォーマンスの問題に悩まされています。3 つのドメイン クラスがあります。

User{
Set authorities
static hasMany = [authorities: Role]
}

Organization{
//more code
}

UserOrganization{
User user
Organization organization
}

ユーザーに多くの役割 (権限) が割り当てられている ('ROLE_ADMIN'、'ROLE_MANAGER')

あるシナリオでは、組織のリストがあり、これらの組織のマネージャー権限 (ROLE_MANAGER) を持つすべてのユーザーを見つける必要があります。

私はこのようにGORMを使ってみました:

UserOrganization.createCriteria().list{
inList('organizaton',organizationList)
//but do not know how to filter out users with ROLE_MANAGER authority
} 

このような単一のGORMクエリでそれを行う方法はありますか? これらの組織のすべてのユーザーのリストを取得し、retainAll{closure} を実行して管理者を除外することもできますが、これは 2 段階のプロセスであり、パフォーマンスのボトルネックが発生します。

4

1 に答える 1

1
UserOrganization.createCriteria().list{
    inList('organizaton',organizationList)
    user {
        inList('authorities',authoritiesList)
    }
} 

ところで。明示的に記述する必要はありませんauthorities。GORM が作成します。

User {
    static hasMany = [authorities: Role]
}

Set権限がまたは他のコレクション型であることを確認したい場合は、次のように書く必要があります。Set authorities

于 2012-12-22T11:33:20.047 に答える