FilterPane plugin: how to filter on hasMany size?

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

FilterPane plugin: how to filter on hasMany size?

Bob Brown
I have two domains: Practice and Doctor.

There exists a 1:n relationship (one practice can have many doctors working
for it). The name is 'doctors.'

Ie:

///
class Doctor {
}

class Practice {
    static hasMany = [
            doctors: Doctor
    ]
}
///

I'd like Filterpane to be able to filter based on doctors.size().

Can this be done?

I have tried adding a getNumDoctors() method to the practice domain, viz:

///
Long getNumDoctors() { doctors.size() }
///

But this didn't work...

Anyone tried this before?

Cheers,

BOB


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: FilterPane plugin: how to filter on hasMany size?

sbglasius
Yes, but you need to mark the numDoctors as transient

static transients = ['numDoctors'] 

/Søren


Med venlig hilsen / Best regards,
Søren Berg Glasius

Hedevej 1, Gl. Rye, DK-8680 Ry, Denmark
Mobile: (+45)40449188, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.


2012/10/31 Bob Brown <[hidden email]>
I have two domains: Practice and Doctor.

There exists a 1:n relationship (one practice can have many doctors working
for it). The name is 'doctors.'

Ie:

///
class Doctor {
}

class Practice {
    static hasMany = [
            doctors: Doctor
    ]
}
///

I'd like Filterpane to be able to filter based on doctors.size().

Can this be done?

I have tried adding a getNumDoctors() method to the practice domain, viz:

///
Long getNumDoctors() { doctors.size() }
///

But this didn't work...

Anyone tried this before?

Cheers,

BOB


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

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: FilterPane plugin: how to filter on hasMany size?

Bob Brown
I tried that.

Didn't work, sadly.

Thanks, anyway.

I'll probably end up doing more filtering on the list returned from the filter service...

Cheers,

Bob

Sent from my iPad

On 31/10/2012, at 9:30 PM, Søren Berg Glasius <[hidden email]> wrote:

Yes, but you need to mark the numDoctors as transient

static transients = ['numDoctors'] 

/Søren


Med venlig hilsen / Best regards,
Søren Berg Glasius

Hedevej 1, Gl. Rye, DK-8680 Ry, Denmark
Mobile: (+45)40449188, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.


2012/10/31 Bob Brown <[hidden email]>
I have two domains: Practice and Doctor.

There exists a 1:n relationship (one practice can have many doctors working
for it). The name is 'doctors.'

Ie:

///
class Doctor {
}

class Practice {
    static hasMany = [
            doctors: Doctor
    ]
}
///

I'd like Filterpane to be able to filter based on doctors.size().

Can this be done?

I have tried adding a getNumDoctors() method to the practice domain, viz:

///
Long getNumDoctors() { doctors.size() }
///

But this didn't work...

Anyone tried this before?

Cheers,

BOB


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

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: FilterPane plugin: how to filter on hasMany size?

gatherer
You cannot use transients! Use derived properties. You can do exactly what you want with filterpane defining a derived property (look it up on docs or this mailing list) that count the numbers of doctors. Derived properties appear to grails like a persisted property, so filterpane can use them to filter queries.
Reply | Threaded
Open this post in threaded view
|

Re: FilterPane plugin: how to filter on hasMany size?

Bob Brown
Thanks.

I had considered derived properties but (wrongly) dismissed them...I thought
they were restricted to simple formulae like 'PRICE * TAX_RATE'.

Then I dived onto The Great Google and came up at:
http://www.jroller.com/eyallupu/entry/hibernate_derived_properties_performan
ce_and

This works nicely for my purpose:

///
    Long numDoctors

    static mapping = {
        numDoctors formula: '(select count(*) from doctor dr where
(dr.practice_id = id))'
    }
///

Thanks to all.

BOB

> -----Original Message-----
> From: gatherer [mailto:[hidden email]]
> Sent: Thursday, 1 November 2012 12:29 AM
> To: [hidden email]
> Subject: [grails-user] Re: FilterPane plugin: how to filter on hasMany
size?
>
> You cannot use transients! Use derived properties. You can do exactly what
> you want with filterpane defining a derived property (look it up on docs
or
> this mailing list) that count the numbers of doctors. Derived properties
> appear to grails like a persisted property, so filterpane can use them to
filter

> queries.
>
>
>
> --
> View this message in context:
> http://grails.1312388.n4.nabble.com/FilterPane-plugin-how-to-filter-on-
> hasMany-size-tp4637215p4637225.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
>



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

    http://xircles.codehaus.org/manage_email