|
Hi,
I have this kind of many to many relation ship. class CategoryTopLevel { String name static hasMany = [offers:Offer] static belongsTo = Offer class Offer implements Comparable{ String name Boolean isactive List<CategoryTopLevel> categoryTopLevels // List<CategorySecondLevel> categorySecondLevelss static hasMany = [ categoryTopLevels: CategoryTopLevel] I wish filter only offers with isactive property and can't find a simple solution. I try in CategoryTopLevelController class CategoryTopLevelController { def view = { def categoryInstance = CategoryTopLevel.get(params.id) categoryInstance.offers } Works but how to filter like categoryInstance.offers.findAllByIsactive(true) categoryInstance.offers.findAllBy* methods doen't work with this set. I think thats more an understanding problem. Invert constructions like Offer.findAllByCategoryTopLevels... doesn't work too. How to filter by Many to Many? Any suggestion? Thanks Vladislav --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
categoryInsntance.offers returns a collection.
What you want to do is something like this: categoryInstance.offers.collect{ it.isactive == true } Bear in mind that many to many can be tricky using the 'grails' way. categoryInstance.offers loads all the offers in memory, and this can be really slow if you have lots of offers in your database.
What you want to do is to create a bridge: class CategoryTopLevelOffer { CategoryTopLevel category Offer offer } Then you can find all offers for a specific category like this:
CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance) You can look at the spring security core plugin for an example of a many to many relationship in this manner.
On Thu, Jul 19, 2012 at 11:50 PM, Vladislav Vorobiev <[hidden email]> wrote: Hi, The Journey Is The Reward. |
|
Thanks a lot. You solution work for me.
Interesting, why the official, document way for many to many don't allow it... Vladislav 2012/7/20 Roberto Guerra <[hidden email]>: > categoryInsntance.offers returns a collection. > > What you want to do is something like this: > > categoryInstance.offers.collect{ it.isactive == true } > > Bear in mind that many to many can be tricky using the 'grails' way. > categoryInstance.offers loads all the offers in memory, and this can be > really slow if you have lots of offers in your database. > What you want to do is to create a bridge: > > class CategoryTopLevelOffer { > CategoryTopLevel category > Offer offer > } > > Then you can find all offers for a specific category like this: > > CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance) > > You can look at the spring security core plugin for an example of a many to > many relationship in this manner. > > > On Thu, Jul 19, 2012 at 11:50 PM, Vladislav Vorobiev > <[hidden email]> wrote: >> >> Hi, >> >> I have this kind of many to many relation ship. >> >> class CategoryTopLevel { >> String name >> static hasMany = [offers:Offer] >> static belongsTo = Offer >> >> >> class Offer implements Comparable{ >> String name >> Boolean isactive >> List<CategoryTopLevel> categoryTopLevels >> // List<CategorySecondLevel> categorySecondLevelss >> static hasMany = [ categoryTopLevels: CategoryTopLevel] >> >> I wish filter only offers with isactive property and can't find a >> simple solution. >> >> I try in CategoryTopLevelController >> >> class CategoryTopLevelController { >> def view = { >> def categoryInstance = CategoryTopLevel.get(params.id) >> categoryInstance.offers >> } >> >> Works but how to filter like >> categoryInstance.offers.findAllByIsactive(true) >> >> categoryInstance.offers.findAllBy* methods doen't work with this set. >> >> I think thats more an understanding problem. >> >> Invert constructions like >> >> Offer.findAllByCategoryTopLevels... doesn't work too. >> >> How to filter by Many to Many? >> >> Any suggestion? >> >> Thanks >> Vladislav >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > > -- > The Journey Is The Reward. -- Best Regards Vlad Vorobiev --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Roberto Guerra
Hi,
by this solution I get instances of CategoryTopLevelOffer I get a list of all real Offer objects like this CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance)*.getOffer() But how to filter database also for Offer.isactive == true together with category this way? Regards Vlad 2012/7/20 Roberto Guerra <[hidden email]>: > categoryInsntance.offers returns a collection. > > What you want to do is something like this: > > categoryInstance.offers.collect{ it.isactive == true } > > Bear in mind that many to many can be tricky using the 'grails' way. > categoryInstance.offers loads all the offers in memory, and this can be > really slow if you have lots of offers in your database. > What you want to do is to create a bridge: > > class CategoryTopLevelOffer { > CategoryTopLevel category > Offer offer > } > > Then you can find all offers for a specific category like this: > > CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance) > > You can look at the spring security core plugin for an example of a many to > many relationship in this manner. > > > On Thu, Jul 19, 2012 at 11:50 PM, Vladislav Vorobiev > <[hidden email]> wrote: >> >> Hi, >> >> I have this kind of many to many relation ship. >> >> class CategoryTopLevel { >> String name >> static hasMany = [offers:Offer] >> static belongsTo = Offer >> >> >> class Offer implements Comparable{ >> String name >> Boolean isactive >> List<CategoryTopLevel> categoryTopLevels >> // List<CategorySecondLevel> categorySecondLevelss >> static hasMany = [ categoryTopLevels: CategoryTopLevel] >> >> I wish filter only offers with isactive property and can't find a >> simple solution. >> >> I try in CategoryTopLevelController >> >> class CategoryTopLevelController { >> def view = { >> def categoryInstance = CategoryTopLevel.get(params.id) >> categoryInstance.offers >> } >> >> Works but how to filter like >> categoryInstance.offers.findAllByIsactive(true) >> >> categoryInstance.offers.findAllBy* methods doen't work with this set. >> >> I think thats more an understanding problem. >> >> Invert constructions like >> >> Offer.findAllByCategoryTopLevels... doesn't work too. >> >> How to filter by Many to Many? >> >> Any suggestion? >> >> Thanks >> Vladislav >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > > -- > The Journey Is The Reward. -- Best Regards Vlad Vorobiev --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
No solution for this topic.
Are there what's the standard way? 2012/7/24 Vladislav Vorobiev <[hidden email]>: > Hi, > > by this solution I get instances of CategoryTopLevelOffer > I get a list of all real Offer objects like this > > CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance)*.getOffer() > > But how to filter database also for Offer.isactive == true together > with category this way? > > Regards > Vlad > > > > 2012/7/20 Roberto Guerra <[hidden email]>: >> categoryInsntance.offers returns a collection. >> >> What you want to do is something like this: >> >> categoryInstance.offers.collect{ it.isactive == true } >> >> Bear in mind that many to many can be tricky using the 'grails' way. >> categoryInstance.offers loads all the offers in memory, and this can be >> really slow if you have lots of offers in your database. >> What you want to do is to create a bridge: >> >> class CategoryTopLevelOffer { >> CategoryTopLevel category >> Offer offer >> } >> >> Then you can find all offers for a specific category like this: >> >> CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance) >> >> You can look at the spring security core plugin for an example of a many to >> many relationship in this manner. >> >> >> On Thu, Jul 19, 2012 at 11:50 PM, Vladislav Vorobiev >> <[hidden email]> wrote: >>> >>> Hi, >>> >>> I have this kind of many to many relation ship. >>> >>> class CategoryTopLevel { >>> String name >>> static hasMany = [offers:Offer] >>> static belongsTo = Offer >>> >>> >>> class Offer implements Comparable{ >>> String name >>> Boolean isactive >>> List<CategoryTopLevel> categoryTopLevels >>> // List<CategorySecondLevel> categorySecondLevelss >>> static hasMany = [ categoryTopLevels: CategoryTopLevel] >>> >>> I wish filter only offers with isactive property and can't find a >>> simple solution. >>> >>> I try in CategoryTopLevelController >>> >>> class CategoryTopLevelController { >>> def view = { >>> def categoryInstance = CategoryTopLevel.get(params.id) >>> categoryInstance.offers >>> } >>> >>> Works but how to filter like >>> categoryInstance.offers.findAllByIsactive(true) >>> >>> categoryInstance.offers.findAllBy* methods doen't work with this set. >>> >>> I think thats more an understanding problem. >>> >>> Invert constructions like >>> >>> Offer.findAllByCategoryTopLevels... doesn't work too. >>> >>> How to filter by Many to Many? >>> >>> Any suggestion? >>> >>> Thanks >>> Vladislav >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >> >> >> >> -- >> The Journey Is The Reward. > > > > -- > Best Regards > Vlad Vorobiev -- Best Regards Vlad Vorobiev --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Ok I found this solution
def cat = CategoryTopLevelOffer.withCriteria { eq('categoryTopLevel', categoryInstance) offer { eq('isactive', true) } } def results = cat*.getOffer() 2012/7/25 Vladislav Vorobiev <[hidden email]>: > No solution for this topic. > Are there what's the standard way? > > 2012/7/24 Vladislav Vorobiev <[hidden email]>: >> Hi, >> >> by this solution I get instances of CategoryTopLevelOffer >> I get a list of all real Offer objects like this >> >> CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance)*.getOffer() >> >> But how to filter database also for Offer.isactive == true together >> with category this way? >> >> Regards >> Vlad >> >> >> >> 2012/7/20 Roberto Guerra <[hidden email]>: >>> categoryInsntance.offers returns a collection. >>> >>> What you want to do is something like this: >>> >>> categoryInstance.offers.collect{ it.isactive == true } >>> >>> Bear in mind that many to many can be tricky using the 'grails' way. >>> categoryInstance.offers loads all the offers in memory, and this can be >>> really slow if you have lots of offers in your database. >>> What you want to do is to create a bridge: >>> >>> class CategoryTopLevelOffer { >>> CategoryTopLevel category >>> Offer offer >>> } >>> >>> Then you can find all offers for a specific category like this: >>> >>> CategoryTopLevelOffer.findAllByCategoryTopLevel(categoryInstance) >>> >>> You can look at the spring security core plugin for an example of a many to >>> many relationship in this manner. >>> >>> >>> On Thu, Jul 19, 2012 at 11:50 PM, Vladislav Vorobiev >>> <[hidden email]> wrote: >>>> >>>> Hi, >>>> >>>> I have this kind of many to many relation ship. >>>> >>>> class CategoryTopLevel { >>>> String name >>>> static hasMany = [offers:Offer] >>>> static belongsTo = Offer >>>> >>>> >>>> class Offer implements Comparable{ >>>> String name >>>> Boolean isactive >>>> List<CategoryTopLevel> categoryTopLevels >>>> // List<CategorySecondLevel> categorySecondLevelss >>>> static hasMany = [ categoryTopLevels: CategoryTopLevel] >>>> >>>> I wish filter only offers with isactive property and can't find a >>>> simple solution. >>>> >>>> I try in CategoryTopLevelController >>>> >>>> class CategoryTopLevelController { >>>> def view = { >>>> def categoryInstance = CategoryTopLevel.get(params.id) >>>> categoryInstance.offers >>>> } >>>> >>>> Works but how to filter like >>>> categoryInstance.offers.findAllByIsactive(true) >>>> >>>> categoryInstance.offers.findAllBy* methods doen't work with this set. >>>> >>>> I think thats more an understanding problem. >>>> >>>> Invert constructions like >>>> >>>> Offer.findAllByCategoryTopLevels... doesn't work too. >>>> >>>> How to filter by Many to Many? >>>> >>>> Any suggestion? >>>> >>>> Thanks >>>> Vladislav >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe from this list, please visit: >>>> >>>> http://xircles.codehaus.org/manage_email >>>> >>>> >>> >>> >>> >>> -- >>> The Journey Is The Reward. >> >> >> >> -- >> Best Regards >> Vlad Vorobiev > > > > -- > Best Regards > Vlad Vorobiev -- Best Regards Vlad Vorobiev --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
