Criteria question...

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Criteria question...

webmediauk
Hey I'm using criteria to create a custom collection which is something like this:

def myCollection = Model.list {
    eq("sitePage", w)
}

My question/problem is "w" is actually "sitePage"s owner, so is there a way to do something like:

def myCollection = Model.list {
    eq("sitePage.owner", w)
}

Many Thanks
Baz
Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

netwiser
Here are some example:

class Model {
  SitePage sitePage
...
}

class SitePage {
    User owner
...
}

def criteria = Model.createCriteria()

def myCollection = criteria.list(max:max, offset:offset){
    eq('sitePage.owner', w)
}


> Date: Thu, 19 Jan 2012 07:04:52 -0800

> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] Criteria question...
>
> Hey I'm using criteria to create a custom collection which is something like
> this:
>
> def myCollection = Model.list {
> eq("sitePage", w)
> }
>
> My question/problem is "w" is actually "sitePage"s owner, so is there a way
> to do something like:
>
> def myCollection = Model.list {
> eq("sitePage.owner", w)
> }
>
> Many Thanks
> Baz
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Criteria-question-tp4310277p4310277.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

webmediauk
Thanks,
I'm using Grails 1.3.7 should that work?
I just get a hibernate error:

org.hibernate.QueryException: could not resolve property: sitePage.owner of: BLAH

Any ideas?
Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

netwiser
Can you please make sure that there is a relationship between SitePage and Owner domains?

Says, in SitePage class, there is a static belongsTo = [owner:Owner]

> Date: Thu, 19 Jan 2012 08:24:20 -0800

> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] RE: Criteria question...
>
> Thanks,
> I'm using Grails 1.3.7 should that work?
> I just get a hibernate error:
>
> org.hibernate.QueryException: could not resolve property: sitePage.owner of:
> BLAH
>
> Any ideas?
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Criteria-question-tp4310277p4310513.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

webmediauk
This post was updated on .
I didn't have the relationship specified like that I had it like this:

class SitePage {
   Owner owner
}

so I changed it to:

class SitePage{
   static belongsTo = [ owner : Owner]
}

I get the same error?
Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

xmly

def criteria = Model.createCriteria()

def myCollection = criteria.list(max:max, offset:offset){
    sitePage  {

            eq('owner',user)
       }
}

try this

On Thu, Jan 19, 2012 at 12:27 PM, webmediauk <[hidden email]> wrote:
I didn't have the relationship specified like that I had it like this:

class SitePage {
  Owner owner
}

so I changed it to:

class Model {
  static belongsTo = [ owner : Owner]
}

I get the same error?

--
View this message in context: http://grails.1312388.n4.nabble.com/Criteria-question-tp4310277p4310718.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

RE: Criteria question...

webmediauk
Yeh that works thanks!