Good news today: Grails has a plug-in for this purpose – it is called the taxonomy plug-in. The developers of this plug-in say that it allows you to apply arbitrary hierarchical categorisation (Taxons) to domain objects. Here is an example of the basic usage:
def book = Book.get(1) // Add the book to the Non-fiction > Autobiography category book.addToTaxonomy(['Non-fiction', 'Autobiography']) def autobiographies = Book.findAllByTaxonomyFamily( ['Non-fiction', 'Autobiography'] )
There is support for arbitrary nesting of Taxons (categories) within unlimited taxonomies, and taxonomies are domain class independent.
So the category “Local” on Author can also be used on Book.
However, you can have different taxonomy graphs aside from the default one, so you might have a taxonomy graph “Location” storing the names of states and cities, and another taxonomy graph “Company type” – and objects having categories in both graphs.
Release 0.1 of the taxonomy plug-in is “alpha” grade. It does not support polymorphism. So querying objects by taxonomy requires you to query the specific class type. This will be resolved in the next release. Also, it does not do caching so it isn’t going to be blazingly fast. Developers say that this will come soon.
Have fun and visit the plug-in page on grails.org.
Diese Artikel könnten Sie noch interessieren:
- Scaffolding in Grails: More than a one-night stand? Scaffolding in Grails (from my point of view) is like...
- Bean Fields for Grails renders form fields easily Bean Fields, a new plugin for Grails, provides a suite...
- Test data for Grails integration tests When you write an integration test for a Grails app,...
- Make your Grails app show content There is a great way to show content from inside...
- “Prettify” your Grails app There are two nice small plug-ins for Grails that make...
Berater, Coach und Trainer für effektive Produktentwicklung
It’s another plug-in from the very prolific Marc Palmer.
–Matt