Grails
  1. Grails
  2. GRAILS-5168

Grails documentation for discriminator has incorrect examples

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.1.1
    • Fix Version/s: None
    • Component/s: Documentation
    • Labels:
      None
    • Environment:
      n/a

      Description

      It appears that the documentation for discriminator has examples that are incorrect. Here is the URL to the documentation.

      http://grails.org/doc/latest/ref/Database%20Mapping/discriminator.html

      The example shows the following...

      class Content {
      ...
      }
      class PodCast extends Content{
      ...
      static mapping =

      { discriminator column:"content_type", value: "audio" }

      }

      However it has been my experience that placing the static mapping in the super class is required or the default column name will be used. I think this is how the example should read in order to specify your own column name for the discriminator.

      class Content {
      ...
      static mapping =

      { discriminator column:"content_type", value: "audio" }

      }
      class PodCast extends Content{
      ...
      }

      Thanks!

        Activity

        Hide
        Graeme Rocher added a comment -

        Assigning all documentation related issues to 1.2 final since they don't represent a change to the codebase

        Show
        Graeme Rocher added a comment - Assigning all documentation related issues to 1.2 final since they don't represent a change to the codebase
        Show
        Joshua Burnett added a comment - fixed here http://github.com/basejump/grails-doc/commit/016aa7fcbc7c1b4170536533c094cafd416b247b
        Hide
        Dave Cramer added a comment -

        I just tried the example in the docs fixed and with postgresql I get the following

        create table entity (id int8 not null, version int8 not null, long2 int8 not null, long1 int8 not null, name varchar(255) not null, parent_id int8, discriminator varchar(-1) not null, primary key (id))

        The class is:

        class Entity {

        Entity parent
        String name
        Long long1
        Long long2

        static mapping =

        { discriminator column:'discriminator',value:"foo" }

        static constraints = {
        }
        }

        Show
        Dave Cramer added a comment - I just tried the example in the docs fixed and with postgresql I get the following create table entity (id int8 not null, version int8 not null, long2 int8 not null, long1 int8 not null, name varchar(255) not null, parent_id int8, discriminator varchar(-1) not null, primary key (id)) The class is: class Entity { Entity parent String name Long long1 Long long2 static mapping = { discriminator column:'discriminator',value:"foo" } static constraints = { } }
        Hide
        kenwei added a comment -

        To avoid the "varchar(-1)" problem in postgresql, I change the discriminator declaration as following:

        class Entity {
        String name

        static mapping =

        { discriminator column: [name:'level', length:50] }

        }

        It finally works, but that causes another problem which is that discriminator value won't work in this class (but works fine in subclasses.)

        Show
        kenwei added a comment - To avoid the "varchar(-1)" problem in postgresql, I change the discriminator declaration as following: class Entity { String name static mapping = { discriminator column: [name:'level', length:50] } } It finally works, but that causes another problem which is that discriminator value won't work in this class (but works fine in subclasses.)

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel Mikusa
          • Votes:
            3 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development