Search code examples
grailsgroovygrails-ormcriteriaprojection

How to query 3 tables in Grails Gorm


I am new to grails framework how to query 3 tables having association between them

    Class A{
    static hasMany = [b:B]
    }

    enter code here

    class B{
    long aId // Id of table A 
    }

    class c{
    B b //B reference
    }

SQL query: select * from C where b_id in (select id from B where a_id='10'_)

Any help will be appreciated.

Solution

  • Straight-forward

    def list = C.withCriteria{
      b{
        eq 'aId', '10'
      }
    }