Skip to content

Commit

Permalink
Merge pull request #358 from teamjft/master
Browse files Browse the repository at this point in the history
Advanced subqueries content section from Gorm grails doc 2.5.0 content has been added to latest GORM documentation
  • Loading branch information
Jeff Scott Brown committed Aug 6, 2015
2 parents f10d1e7 + d0616d4 commit 84dbcdb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/en/guide/GORM/querying/whereQueries.gdoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def query = Person.where {
}
{code}



h4. Query Composition

Since the return value of the @where@ method is a [DetachedCriteria|guide:detachedCriteria] instance you can compose new queries from the original query:
Expand Down Expand Up @@ -252,6 +254,56 @@ Person.where {
{code}


h4. More Advanced Subqueries in GORM

The support for subqueries has been extended. You can now use in with nested subqueries

{code}
def results = Person.where {
firstName in where { age < 18 }.firstName
}.list()
{code}

Criteria and where queries can be seamlessly mixed:

{code}
def results = Person.withCriteria {
notIn "firstName", Person.where { age < 18 }.firstName
}
{code}

Subqueries can be used with projections:

{code}
def results = Person.where {
age > where { age > 18 }.avg('age')
}
{code}

Correlated queries that span two domain classes can be used:
{code}
def employees = Employee.where {
region.continent in ['APAC', "EMEA"]
}.id()
def results = Sale.where {
employee in employees && total > 100000
}.employee.list()
{code}

And support for aliases (cross query references) using simple variable declarations has been added to where queries:
{code}
def query = Employee.where {
def em1 = Employee
exists Sale.where {
def s1 = Sale
def em2 = employee
return em2.id == em1.id
}.id()
}
def results = query.list()
{code}


h4. Other Functions

There are several functions available to you within the context of a query. These are summarized in the table below:
Expand Down
23 changes: 23 additions & 0 deletions src/en/ref/Command Line/create-hibernate-cfg-xml.gdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
h3. Purpose

The create-hibernate-cfg-xml command will create a hibernate.cfg.xml file for custom Hibernate mappings.

h3. Examples

{code}
grails create-hibernate-cfg-xml
{code}

h3. Description

Creates a hibernate.cfg.xml file in the grails-app/conf/hibernate directory. You can add <mapping> elements there to reference annotated Java domain classes, classes mapped by hbm.xml files, or hbm.xml files containing <database-object> elements defining custom DDL that's not supported by GORM.

Usage:

{code}
grails create-hibernate-cfg-xml
{code}

Fired Events:

* CreatedFile - When the file is created

0 comments on commit 84dbcdb

Please sign in to comment.