Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you use a natural id you have to use the <a href="http://grails.org/doc/latest/ref/Domain%20Classes/findBy.html" rel="noreferrer">findBy</a> method instead of the <a href="http://grails.org/doc/latest/ref/Domain%20Classes/get.html" rel="noreferrer">get</a> method as demonstrated in this test:</p> <pre><code>def user = new User(login: "test") assertNotNull user.save(flush: true) user = User.findByLogin("test") assertNotNull user assertEquals "test", user.login </code></pre> <p>Alternately you could use a single field <a href="http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.5.2.5%20Composite%20Primary%20Keys" rel="noreferrer">composite id</a> mapping:</p> <pre><code>class User implements Serializable { String login static hasMany = [apps: Application] static constraints = { } static mapping = { id composite: ['login'] } } </code></pre> <p>Note that <a href="http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.5.2.5%20Composite%20Primary%20Keys" rel="noreferrer">composite id</a> domain classes are required to <em>implement Serializable</em>.</p> <p>The test for the <a href="http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.5.2.5%20Composite%20Primary%20Keys" rel="noreferrer">composite id</a> would be:</p> <pre><code>def user = new User(login: "test") assertNotNull user.save(flush: true) user = User.get(new User(login: "test")) assertNotNull user assertEquals "test", user.login </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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