Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Linux, Grails 1.0.4, Java6

      Description

      Scaffolding of domain classes containing a composite primary key does not work.
      The the controller currently only works with simple integer primary keys.

        Activity

        Hide
        Robert Watts added a comment -

        Will this issue be planned for any future release?

        Show
        Robert Watts added a comment - Will this issue be planned for any future release?
        Hide
        Horst Krause added a comment -

        I implemented a semi-generateable solution, perhaps it helps.

        add to DomainClass.groovy template

        static @artifact.name@ getComposite(String compositeId)

        { return @artifact.name@.get(compositeId) }

        will be after generation
        static Author getComposite(String compositeId)

        { return Author.get(compositeId) }

        in Controller.groovy template replace all Domainclass.get() by getComposite()

        This will still work for non-composite. For composite PK implement the getComposite in addition to set/get ID and the generated views and controllers will work.

        e.g.

        void setId(String compositeId)

        { person.id = new Long(getPersonFromId(compositeId)) project.id = new Long(getProjectFromId(compositeId)) level.id = new Long(getLevelFromId(compositeId)) }

        static String getPersonFromId(String compositeId)

        { return compositeId.substring(0,compositeId.indexOf("-")); }

        static String getProjectFromId(String compositeId)

        { return compositeId.substring(compositeId.indexOf("-")+1,compositeId.lastIndexOf("-")); }

        static String getLevelFromId(String compositeId)

        { return compositeId.substring(compositeId.lastIndexOf("-")+1); }

        String getId()

        { return person.id + "-" + project.id + "-" + level.id; }

        static UserRight getComposite(String compositeId)

        { return UserRight.get( new UserRight( person:Person.get(UserRight.getPersonFromId(compositeId)), project:Project.get(UserRight.getProjectFromId(compositeId)), level:AccessLevel.get(UserRight.getLevelFromId(compositeId)) ) ); }

        Show
        Horst Krause added a comment - I implemented a semi-generateable solution, perhaps it helps. add to DomainClass.groovy template static @artifact.name@ getComposite(String compositeId) { return @artifact.name@.get(compositeId) } will be after generation static Author getComposite(String compositeId) { return Author.get(compositeId) } in Controller.groovy template replace all Domainclass.get() by getComposite() This will still work for non-composite. For composite PK implement the getComposite in addition to set/get ID and the generated views and controllers will work. e.g. void setId(String compositeId) { person.id = new Long(getPersonFromId(compositeId)) project.id = new Long(getProjectFromId(compositeId)) level.id = new Long(getLevelFromId(compositeId)) } static String getPersonFromId(String compositeId) { return compositeId.substring(0,compositeId.indexOf("-")); } static String getProjectFromId(String compositeId) { return compositeId.substring(compositeId.indexOf("-")+1,compositeId.lastIndexOf("-")); } static String getLevelFromId(String compositeId) { return compositeId.substring(compositeId.lastIndexOf("-")+1); } String getId() { return person.id + "-" + project.id + "-" + level.id; } static UserRight getComposite(String compositeId) { return UserRight.get( new UserRight( person:Person.get(UserRight.getPersonFromId(compositeId)), project:Project.get(UserRight.getProjectFromId(compositeId)), level:AccessLevel.get(UserRight.getLevelFromId(compositeId)) ) ); }
        Hide
        Graeme Rocher added a comment -

        There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

        for 1.2 final only issues considered blocking will now be fixed

        Show
        Graeme Rocher added a comment - There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed
        Hide
        Horst Krause added a comment -

        Unfortunately since Grails 1.3 the described workaround does not work any longer, because overwriting the getId() method will break the generation of views and controllers.

        I modified the workaround and published it here:
        http://code.google.com/p/glossy-templates/

        Show
        Horst Krause added a comment - Unfortunately since Grails 1.3 the described workaround does not work any longer, because overwriting the getId() method will break the generation of views and controllers. I modified the workaround and published it here: http://code.google.com/p/glossy-templates/

          People

          • Assignee:
            Unassigned
            Reporter:
            Andreas Stahlbauer
          • Votes:
            13 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated: