Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm still trying to understand your domain; you may be overcomplicating things a bit. Would this basic model work? If not, can you explain why? I'll update my example if I can better understand your conditions.</p> <p><em>Edit - updated example given the comments below.</em></p> <pre><code>class Cage { static belongsTo = [zoo: Zoo] // a cage belongs to a single particular Zoo Species species // a cage has a single Species String name } class Zoo { static hasMany = [cages: Cage] String name } class Species { static hasMany = [cages: Cage] // a species can be in many different cages String name } // one way of representing histories class ResidenceHistory = { Species species Cage cage DateTime from DateTime until } </code></pre> <p>Here's how you might use the domain, then:</p> <pre><code>def sanDiego = new Zoo(name: 'San Diego Zoo').save() def aviary = new Cage(name: 'Aviary', zoo: sanDiego).save() def elephantCage = new Cage(name: 'Elephant Area, Cage 5', zoo: sanDiego).save() def bird = new Species(name: 'Blue-Footed Booby', cage: aviary).save() def elephant = new Species(name: 'Asian Elephant', cage: elephantCage).save() new ResidenceHistory(species: bird, cage: aviary, from: new DateTime(), to: new DateTime().plusDays(20)).save() </code></pre> <p>To answer your listed questions specifically:</p> <ol> <li>It depends - usually I'd prefer using the database's relational capabilities instead of storing maps in the database. It's much easier to work with the raw data if they aren't serialized Java objects.</li> <li>See my example above.</li> <li>This shouldn't matter unless performance becomes an issue. Use the solution that makes the most sense and is the easiest to maintain, and if you find that it causes performance problems, profile your application and fix the problems individually.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload