Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:02:29+00:00 2026-05-23T12:02:29+00:00

I am trying to create a Model to pass to a gsp view. I

  • 0

I am trying to create a Model to pass to a gsp view. I would like to do a sub query across two tables. I have two domains, alum_profile and alum_position. alum_profile has many alum_position’s. alum_position belongs to alum_profile. In SQL if I wanted to create a result set, I would have something like this:

Select count(id), 
 (Select CONCAT(first_name, ' ', last_name)
    From alum_profile
    where 
    alum_profile_id =alum_profile.id ) as Person        
 FROM alum_position
 GROUP BY  alum_profile_id
 ORDER BY count(id) DESC      

How do I do this with HQL and create a model that can be passed to a gsp View.

Thanks for your help
jason
I am using Spring Source, with MySQL and writing in groovy on grails

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:02:29+00:00Added an answer on May 23, 2026 at 12:02 pm

    From what I’ve read of your question, you want to display a list of the Profile’s names, along with how many Positions each Profile has, sorted by the number of positions, desc.

    First, you need Models:

    class AlumProfile {
       String first_name
       String last_name
    
       def hasMany = [positions: AlumPosition]
    };
    
    class AlumPosition {
       String name  // I just added this, no idea what you need in here
    
       def belongsTo=AlumProfile
    };
    

    Now you want to create a list of the AlumProfiles sorted by position count. In your controller, you need:

    def allByPositionCount = {
       def profiles = AlumProfile.list().sort( [compare: { a,b -> a.positions.size().compareTo( b.positions.size() ) }] as Comparator );
       [ profiles: profiles ]
    }
    

    This will render the allByPositionCount.gsp with the model containing the “profiles” member that is the list of profiles in the correct order, so something like:

    <g:each in="${profiles}" var="profile" >
        ${profile.first_name} ${profile.last_name} has ${profiles.positions.size()} positions
    </g:each>
    

    should render what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to pass a model across views Here is
I'm trying to create a model instance from my code, and I pass all
I am trying to create an ActiveRecord model called 'Search' without a table. I
I'm trying to create a Django model that handles the following: An Item can
I am trying to create a mapping file for the following Model using Fluent
At the moment I'm trying to create a kind of model in vb.net which
I have a model, Director with two DateFields, and two subclasses (code below). I
I have a model called Category which looks like this: class Category < ActiveRecord::Base
How to create dynamic table model in J2ME? like from arrays i use kxml
I'm trying to pass some parameters (count) from a form to a model. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.