0

現時点では、ドメイン オブジェクト Product のコントローラ リスト メソッドは次のとおりです。

def list(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    [productInstanceList: Product.list(params), productInstanceTotal: Product.count()]
}

これにさらに制約を加えたいと思います。具体的には、ログインしているユーザーを取得したい。これは、Manager と呼ばれるドメイン エンティティと M:1 の関係にあります。Manager は、ドメイン エンティティ Company に対して M:M の関係を持っています。会社は製品と 1:M の関係にあります。そのため、適切な会社の製品のみを返品したいと考えています。

私は次のことから始めます:

def list(Integer max) {
// 1. Get logged in user. 
def user = springSecurityService.currentUser;
    // 2. Get corresponding manager.
    Manager mgr = user.getManager();
    // 3. Get corresponding companies
    companies = mgr.getCompanies();

    // 4. Get products for all companies - not sure smart way to get this.
    // 5. Need to add the products to the query
    ...
}

ご覧のとおり、ステップ 4、5 で行き詰まります。生の SQL を使用して、すべてのユーザーのマネージャーの会社の製品を表すために結合し、これをwhere述語として入れて、製品テーブルにヒットします。

しかし、grails/groovy ソリューションが必要です。paramsまた、このコントローラーはparamsクエリに渡されるものを注入することもできるため、クエリに を保持する必要があります。

任意のヒント?

4

1 に答える 1