Quantcast

Grails where queries from static context?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grails where queries from static context?

marcopas
Hi there,

according to the Grails (2.1.1) documentation i should be able to
create pre-defined where queries like below:

class Person {
    String firstName
    String lastName

    static simpsons = where {
         lastName == "Simpson"
    }
    …
}

And use it like:

Person.simpsons.each {
    println it.firstName
}

However whatever i try, Grails/Java keeps telling me that i cannot
access non static content from a static reference which i understand
:) But how can i achieve something such as described in the docs?
I want to have predefined where queries in my domain classes that i can use.

/Marco

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

    http://xircles.codehaus.org/manage_email


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

Re: Grails where queries from static context?

sergiomichels
Did you tried named queries?  http://grails.org/doc/2.1.0/ref/Domain%20Classes/namedQueries.html 
--
Sérgio Michels



On Mon, Sep 17, 2012 at 11:26 AM, Marco Pas <[hidden email]> wrote:
Hi there,

according to the Grails (2.1.1) documentation i should be able to
create pre-defined where queries like below:

class Person {
    String firstName
    String lastName

    static simpsons = where {
         lastName == "Simpson"
    }
    …
}

And use it like:

Person.simpsons.each {
    println it.firstName
}

However whatever i try, Grails/Java keeps telling me that i cannot
access non static content from a static reference which i understand
:) But how can i achieve something such as described in the docs?
I want to have predefined where queries in my domain classes that i can use.

/Marco

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

    http://xircles.codehaus.org/manage_email



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

Re: Grails where queries from static context?

marcopas
Yep i did, that works, but i was triggered by the simplicity and
expression of the where queries. According to the docs it should work
so i am wondering what i am doing wrong.

/Marco

2012/9/17 Sergio Michels <[hidden email]>:

> Did you tried named queries?
> http://grails.org/doc/2.1.0/ref/Domain%20Classes/namedQueries.html
> --
> Sérgio Michels
>
>
>
> On Mon, Sep 17, 2012 at 11:26 AM, Marco Pas <[hidden email]> wrote:
>>
>> Hi there,
>>
>> according to the Grails (2.1.1) documentation i should be able to
>> create pre-defined where queries like below:
>>
>> class Person {
>>     String firstName
>>     String lastName
>>
>>     static simpsons = where {
>>          lastName == "Simpson"
>>     }
>>     …
>> }
>>
>> And use it like:
>>
>> Person.simpsons.each {
>>     println it.firstName
>> }
>>
>> However whatever i try, Grails/Java keeps telling me that i cannot
>> access non static content from a static reference which i understand
>> :) But how can i achieve something such as described in the docs?
>> I want to have predefined where queries in my domain classes that i can
>> use.
>>
>> /Marco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>

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

    http://xircles.codehaus.org/manage_email


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

Re: Grails where queries from static context?

Jeff Scott Brown
In reply to this post by marcopas

On Sep 17, 2012, at 9:26 AM, Marco Pas wrote:

> Hi there,
>
> according to the Grails (2.1.1) documentation i should be able to
> create pre-defined where queries like below:
>
> class Person {
>    String firstName
>    String lastName
>
>    static simpsons = where {
>         lastName == "Simpson"
>    }
>    …
> }
>
> And use it like:
>
> Person.simpsons.each {
>    println it.firstName
> }
>
> However whatever i try, Grails/Java keeps telling me that i cannot
> access non static content from a static reference which i understand
> :) But how can i achieve something such as described in the docs?
> I want to have predefined where queries in my domain classes that i can use.
>
> /Marco



What you have there should work.  I just verified that it does work.  There must be something else going on in your code that may be causing a problem.  

Is your IDE complaining or is Grails complaining?



jsb
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


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

    http://xircles.codehaus.org/manage_email


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

Re: Grails where queries from static context?

longwa
Unless parts of GRAILS-9280 have been included in 2.1.1, the where
chaining may not work correctly. Specifically, chaining works if the
chained query is in the same scope but doesn't work in the example
above where you define a static where query and then chain in the
manner above.

See bullet item #6 on http://jira.grails.org/browse/GRAILS-9280.

Graeme did commit a fix for this item to the grails-data-mapping
project, but I'm not sure if that's part of 2.1.1.

-Aaron

On Tue, Sep 18, 2012 at 12:59 PM, Jeff Brown <[hidden email]> wrote:

>
> On Sep 17, 2012, at 9:26 AM, Marco Pas wrote:
>
>> Hi there,
>>
>> according to the Grails (2.1.1) documentation i should be able to
>> create pre-defined where queries like below:
>>
>> class Person {
>>    String firstName
>>    String lastName
>>
>>    static simpsons = where {
>>         lastName == "Simpson"
>>    }
>>    …
>> }
>>
>> And use it like:
>>
>> Person.simpsons.each {
>>    println it.firstName
>> }
>>
>> However whatever i try, Grails/Java keeps telling me that i cannot
>> access non static content from a static reference which i understand
>> :) But how can i achieve something such as described in the docs?
>> I want to have predefined where queries in my domain classes that i can use.
>>
>> /Marco
>
>
>
> What you have there should work.  I just verified that it does work.  There must be something else going on in your code that may be causing a problem.
>
> Is your IDE complaining or is Grails complaining?
>
>
>
> jsb
> --
> Jeff Brown
> SpringSource
> http://www.springsource.com/
>
> Autism Strikes 1 in 166
> Find The Cause ~ Find The Cure
> http://www.autismspeaks.org/
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

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

    http://xircles.codehaus.org/manage_email


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

Re: Grails where queries from static context?

Jeff Scott Brown

On Sep 18, 2012, at 1:22 PM, Aaron Long wrote:

> Unless parts of GRAILS-9280 have been included in 2.1.1, the where
> chaining may not work correctly. Specifically, chaining works if the
> chained query is in the same scope but doesn't work in the example
> above where you define a static where query and then chain in the
> manner above.
>
> See bullet item #6 on http://jira.grails.org/browse/GRAILS-9280.
>
> Graeme did commit a fix for this item to the grails-data-mapping
> project, but I'm not sure if that's part of 2.1.1.
>
> -Aaron
>


I don't think the OP is using chaining.  Is he?



jsb

--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


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

    http://xircles.codehaus.org/manage_email


Loading...