Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well first of all lets correct it, you can use <code>inheritance</code> in this case. You just need to change the convention of <code>has a</code> relationship to <code>is a</code> relationship.</p> <p>Few factors to keep note of: 1. Grails works on convention over configuration. 2. You can use GORM which wraps the persistence layer and creates an Object Mapping for the underlying persistence layer with the help of Hibernate.</p> <p>As per your functional requirement:-</p> <p>If you do not want to have the <code>User</code> as part of persistence you can have an <code>abstract</code> class <code>User</code> which can hold the common properties of the User including the <code>openId</code> attribute. It has to be placed in <code>src\groovy</code> directory as per convention (since the base class is abstract, dependency injection will be defied)</p> <p>The same goes for <code>Property</code>. Abstract <code>Property</code> class in <code>src\groovy</code>.</p> <p>Now coming to the business models, <code>extend</code> each of the concrete entities (<code>domain</code> classes) from the <code>abstract</code> parent.</p> <p>Summary:-</p> <ul> <li><p>Create grails app</p></li> <li><p>Under src\groovy(for example, I am considering a basic structure):</p></li> </ul> <p>User.groovy:-</p> <pre><code>abstract class User{ String name String emailId OpenID openId } </code></pre> <p>Property.groovy:-</p> <pre><code>abstract class Property{ String propertyName } </code></pre> <ul> <li>Under <code>grails-app/domain</code>:</li> </ul> <p>Librariran.groovy:-</p> <pre><code>class Librarian extends User{ //Attributes specific to Librariran static constraints = { } static mapping = { } } </code></pre> <p>Book.groovy:-</p> <pre><code>class Book extends Property{ //Attributes specific to Book static constraints = { } static mapping = { } } </code></pre> <p>So on and so forth. Groovy objects under grails-app/domain are considered concrete entities by Grails convention. More information you can obviously find <a href="http://grails.org/doc/latest/guide/GORM.html">here</a>. You can also use composition if you come across scenarios, in fact I already mentioned that in <code>User</code> having <code>OpenId</code>.</p> <p>Note:- This is context to latest version of Grails (> 2.x)</p>
    singulars
    1. This table or related slice is empty.
    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