Created
October 5, 2012 14:10
-
-
Save pjagielski/3839991 to your computer and use it in GitHub Desktop.
Projections Grails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Link.withCriteria { | |
votes { | |
projections { | |
groupProperty("link") | |
sum("score") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Link.withCriteria { | |
createAlias('votes', 'v') | |
projections { | |
groupProperty('v.link') | |
sum('v.score', 'score') | |
} | |
order 'score', 'desc' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LinkStatistics { | |
static belongsTo = [link: Link] | |
Integer score | |
Date dateCreated | |
static mapping = { | |
table("v_link_statistics") | |
link(fetch: FetchMode.EAGER) | |
version(false) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinkStatistics.list(sort: 'score', order: 'desc') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinkStatistics.withCriteria { | |
createAlias('link','l') | |
order('score', 'desc') | |
order('dateCreated', 'desc') | |
order('id', 'desc') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW v_link_statistics AS | |
SELECT l.id, l.id as link_id, sum(nvl(v.score,0)), l.date_created | |
FROM link l LEFT JOIN vote v ON v.link_id = v.id | |
GROUP by l.id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment