Quantcast

Named queries inside a criteria with joins

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Named queries inside a criteria with joins

lmivan
Hi all,

I was wondering if it is possible to use a named query inside a criteria with joins. Let me use an example:

class User {
   ...
   String name
   Boolean isDeleted

   static namedQueries = {
      validUsers {
          eq 'isDeleted', false
       }
    }   
}

class Tweet {
   ...
   String text
   User user
}

Inside a controller or a service I can get all valid users or all the valid users with name "john"

User.validUsers.list()
User.validUsers.findAllByName("John")

But, what if I want to get all tweets of valid users?. I would like to do something like:

def tweets = Tweet.createCriteria().list() {
   user.validUsers

   // or maybe
   user.validUsers()

   // or
   user {
      validUsers()
   }

But none of this options seems to work. Is possible to use a named query like that? or I need to do something like:

def tweets = Tweet.createCriteria().list() {
   user {
      eq 'isDeleted', false
   }
}

I want to write my "validUser" constraint only in one place and use it all over my application.

Thanks and regards, Iván.

--
El Blog de Iván López - http://lopezivan.blogspot.com
Twitter - http://www.twitter.com/ilopmar



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Named queries inside a criteria with joins

burtbeckwith
Please ask usage questions on the User list.

Burt
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Named queries inside a criteria with joins

lmivan
I think this is not an usage question but a question that I don't know if it is implemented in grails.

Thanks and regards, Iván.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Named queries inside a criteria with joins

burtbeckwith
Exactly - you're asking about using GORM. The dev list is for discussion of Grails development itself, not using its features.

Burt

lmivan wrote
I think this is not an usage question but a question that I don't know if it is implemented in grails.

Thanks and regards, Iván.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Named queries inside a criteria with joins

lmivan
Ok Burt, sorry for that. The thing is that I posted the question in the user list a few days ago but, as no one anwser and I wasn't sure if that was the correct list, I resend it to the dev list.

Regards, Iván.
--
El Blog de Iván López - http://lopezivan.blogspot.com
Twitter - http://www.twitter.com/ilopmar



On Thu, Aug 9, 2012 at 10:15 PM, burtbeckwith [via Grails] <[hidden email]> wrote:
Exactly - you're asking about using GORM. The dev list is for discussion of Grails development itself, not using its features.

Burt

lmivan wrote
I think this is not an usage question but a question that I don't know if it is implemented in grails.

Thanks and regards, Iván.



If you reply to this email, your message will be added to the discussion below:
http://grails.1312388.n4.nabble.com/Named-queries-inside-a-criteria-with-joins-tp4632967p4632980.html
To start a new topic under Grails - dev, email [hidden email]
To unsubscribe from Grails - dev, click here.
NAML

Loading...