Quantcast

criteria: querying (possibly blank) properties of associations

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

criteria: querying (possibly blank) properties of associations

Benjamin Klein
Given a class Foo with

Bar bar

the docs seem to say that I should be able to do:

def c = Foo.createCriteria()
def fooInstanceList
               
fooInstanceList = c.list{
    or{
        eq('property', var)
        eq('otherProperty', var)
        bar{
            eq('otherOtherProperty', var)
        }
    }
}

But I am getting two problems with this:

1) It’s case sensitive; a Foo with property "Bas" won’t be found if I give the var “bas” and

2) It’s not returning results where the otherOtherProperty of bar matches.

Am I doing something wrong here? (If so, how else should this be done?)

Thanks!

--
b



---------------------------------------------------------------------
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
star

Re: criteria: querying (possibly blank) properties of associations

gauravchauhan
Turn the sql logging on and see what queries are being fired by criteria.

Take a look at Configuration Docs

Regards
Gaurav Chauhan



On Tue, Sep 27, 2011 at 9:31 PM, Benjamin Klein <[hidden email]> wrote:
Given a class Foo with

Bar bar

the docs seem to say that I should be able to do:

def c = Foo.createCriteria()
def fooInstanceList

fooInstanceList = c.list{
   or{
       eq('property', var)
       eq('otherProperty', var)
       bar{
           eq('otherOtherProperty', var)
       }
   }
}

But I am getting two problems with this:

1) It’s case sensitive; a Foo with property "Bas" won’t be found if I give the var “bas” and

2) It’s not returning results where the otherOtherProperty of bar matches.

Am I doing something wrong here? (If so, how else should this be done?)

Thanks!

--
b



---------------------------------------------------------------------
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
star

Re: criteria: querying (possibly blank) properties of associations

Benjamin Klein
Well, that’s certainly an obvious first step, but I forgot to do it. So thanks for pointing that out.

I should mention that I am actually checking two properties of Bar. I want to get a Foo instance whenever one of its two properties matches *or* one of two properties of its Bar matches. The logging reveals that Hibernate is checking for either property or otherProperty matching on the fooInstance, and then checking whether both of the Bar instance’s properties match. They never do, so it couldn’t find any of those.

Right now, I have this:

users = c.list{
    or{
        eq('username', var)
        eq('email', var)
        profile{
    or{
                eq('firstName', var)
    eq('lastName', var)
            }
        }
    }
}

This finds an instance if any of those properties match the parameter. If two properties match, though, it returns the instance twice. I can fix this by running unique() on the List afterwards, but that seems somewhat odd to have to do.

So the point is that this works, and I am probably doing something wrong. :)

Thanks!

--
b

On Sep 27, 2011, at 11:10 AM, Gaurav Chauhan wrote:

Turn the sql logging on and see what queries are being fired by criteria.

Take a look at Configuration Docs

Regards
Gaurav Chauhan



On Tue, Sep 27, 2011 at 9:31 PM, Benjamin Klein <[hidden email]> wrote:
Given a class Foo with

Bar bar

the docs seem to say that I should be able to do:

def c = Foo.createCriteria()
def fooInstanceList

fooInstanceList = c.list{
   or{
       eq('property', var)
       eq('otherProperty', var)
       bar{
           eq('otherOtherProperty', var)
       }
   }
}

But I am getting two problems with this:

1) It’s case sensitive; a Foo with property "Bas" won’t be found if I give the var “bas” and

2) It’s not returning results where the otherOtherProperty of bar matches.

Am I doing something wrong here? (If so, how else should this be done?)

Thanks!

--
b



---------------------------------------------------------------------
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
star

Re: criteria: querying (possibly blank) properties of associations

olivertynes
http://grails.org/doc/latest/ref/Domain%20Classes/createCriteria.html

You're looking for "listDistinct".

-Oliver

On Tue, Sep 27, 2011 at 11:34 PM, Benjamin Klein <[hidden email]> wrote:

> Well, that’s certainly an obvious first step, but I forgot to do it. So
> thanks for pointing that out.
> I should mention that I am actually checking two properties of Bar. I want
> to get a Foo instance whenever one of its two properties matches *or* one of
> two properties of its Bar matches. The logging reveals that Hibernate is
> checking for either property or otherProperty matching on the fooInstance,
> and then checking whether both of the Bar instance’s properties match. They
> never do, so it couldn’t find any of those.
> Right now, I have this:
> users = c.list{
>     or{
>         eq('username', var)
>         eq('email', var)
>         profile{
>     or{
>                 eq('firstName', var)
>     eq('lastName', var)
>             }
>         }
>     }
> }
> This finds an instance if any of those properties match the parameter. If
> two properties match, though, it returns the instance twice. I can fix this
> by running unique() on the List afterwards, but that seems somewhat odd to
> have to do.
> So the point is that this works, and I am probably doing something wrong. :)
> Thanks!
> --
> b
> On Sep 27, 2011, at 11:10 AM, Gaurav Chauhan wrote:
>
> Turn the sql logging on and see what queries are being fired by criteria.
>
> Take a look at Configuration Docs
>
> Regards
> Gaurav Chauhan
>
>
>
> On Tue, Sep 27, 2011 at 9:31 PM, Benjamin Klein <[hidden email]>
> wrote:
>>
>> Given a class Foo with
>>
>> Bar bar
>>
>> the docs seem to say that I should be able to do:
>>
>> def c = Foo.createCriteria()
>> def fooInstanceList
>>
>> fooInstanceList = c.list{
>>    or{
>>        eq('property', var)
>>        eq('otherProperty', var)
>>        bar{
>>            eq('otherOtherProperty', var)
>>        }
>>    }
>> }
>>
>> But I am getting two problems with this:
>>
>> 1) It’s case sensitive; a Foo with property "Bas" won’t be found if I give
>> the var “bas” and
>>
>> 2) It’s not returning results where the otherOtherProperty of bar matches.
>>
>> Am I doing something wrong here? (If so, how else should this be done?)
>>
>> Thanks!
>>
>> --
>> b
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>
>



--
*****
Oliver Tynes
Developer
Uni CIPR -- www.cipr.uni.no
55588266
*****

---------------------------------------------------------------------
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
star

Re: criteria: querying (possibly blank) properties of associations

Benjamin Klein
Yes. That is exactly what I wanted. Thanks!

--
b

On Sep 28, 2011, at 3:55 AM, Oliver Severin Tynes wrote:

> http://grails.org/doc/latest/ref/Domain%20Classes/createCriteria.html
>
> You're looking for "listDistinct".
>
> -Oliver
>
> On Tue, Sep 27, 2011 at 11:34 PM, Benjamin Klein <[hidden email]> wrote:
>> Well, that’s certainly an obvious first step, but I forgot to do it. So
>> thanks for pointing that out.
>> I should mention that I am actually checking two properties of Bar. I want
>> to get a Foo instance whenever one of its two properties matches *or* one of
>> two properties of its Bar matches. The logging reveals that Hibernate is
>> checking for either property or otherProperty matching on the fooInstance,
>> and then checking whether both of the Bar instance’s properties match. They
>> never do, so it couldn’t find any of those.
>> Right now, I have this:
>> users = c.list{
>>     or{
>>         eq('username', var)
>>         eq('email', var)
>>         profile{
>>     or{
>>                 eq('firstName', var)
>>     eq('lastName', var)
>>             }
>>         }
>>     }
>> }
>> This finds an instance if any of those properties match the parameter. If
>> two properties match, though, it returns the instance twice. I can fix this
>> by running unique() on the List afterwards, but that seems somewhat odd to
>> have to do.
>> So the point is that this works, and I am probably doing something wrong. :)
>> Thanks!
>> --
>> b
>> On Sep 27, 2011, at 11:10 AM, Gaurav Chauhan wrote:
>>
>> Turn the sql logging on and see what queries are being fired by criteria.
>>
>> Take a look at Configuration Docs
>>
>> Regards
>> Gaurav Chauhan
>>
>>
>>
>> On Tue, Sep 27, 2011 at 9:31 PM, Benjamin Klein <[hidden email]>
>> wrote:
>>>
>>> Given a class Foo with
>>>
>>> Bar bar
>>>
>>> the docs seem to say that I should be able to do:
>>>
>>> def c = Foo.createCriteria()
>>> def fooInstanceList
>>>
>>> fooInstanceList = c.list{
>>>    or{
>>>        eq('property', var)
>>>        eq('otherProperty', var)
>>>        bar{
>>>            eq('otherOtherProperty', var)
>>>        }
>>>    }
>>> }
>>>
>>> But I am getting two problems with this:
>>>
>>> 1) It’s case sensitive; a Foo with property "Bas" won’t be found if I give
>>> the var “bas” and
>>>
>>> 2) It’s not returning results where the otherOtherProperty of bar matches.
>>>
>>> Am I doing something wrong here? (If so, how else should this be done?)
>>>
>>> Thanks!
>>>
>>> --
>>> b
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>>
>
>
>
> --
> *****
> Oliver Tynes
> Developer
> Uni CIPR -- www.cipr.uni.no
> 55588266
> *****
>
> ---------------------------------------------------------------------
> 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


Loading...