gorma icon indicating copy to clipboard operation
gorma copied to clipboard

build error when I use ArrayOf in payload and Gorma

Open MohamedFAhmed opened this issue 8 years ago • 7 comments

We're expecting in one of our payloads and object that has basic attributes and array of objects in it. . However, I get these errors when we use gorma.

**models/clc.go:178: cannot use payload.Containers (type string) as type []Container in assignment models/clc.go:203: cannot use payload.Containers (type string) as type []Container in assignment

This is how the payload is defined

`var ClcPayload = Type("ClcPayload", func() {
    Attribute("name", String, func() {
        MinLength(1)
        MaxLength(1024)
    })
    Attribute("labels", func(){
        ArrayOf(LabelPayload)
    })
    Attribute("description", String, func(){
        MinLength(0)
        MaxLength(1024)
    })
    Attribute("replicas", Integer, func(){
        Minimum(1)
        Maximum(10)
    })
    Attribute("containers", func(){
        ArrayOf(ContainerPayload)
    })
})`

var ContainerPayload = Type("ContainerPayload", func() {
    Attribute("name", String, func() {
        MinLength(1)
        MaxLength(1024)
    })
    Attribute("labels", func(){
        ArrayOf(LabelPayload)
    })
    Attribute("description", String, func(){
        MinLength(0)
        MaxLength(1024)
    })
    Attribute("image_url", String)

    Attribute("ports", func(){
        ArrayOf(PortPayload)
    })

    Attribute("envs", func(){
        ArrayOf(EnvPayload)
    })

    Attribute("commands", func(){
        ArrayOf(String)
    })
    Attribute("icus", Integer)
    Attribute("memory", Integer)
    Attribute("replicas", Integer, func(){
        Minimum(1)
        Maximum(10)
    })
    //Attribute("volumes", ArrayOf(VolumePayload))
})`

This is the definition of our data model

Model("Clc", func() {
      BuildsFrom(func() {
                Payload("clc", "create")
                Payload("clc", "update")
            })
      RendersTo(Clc)
      HasMany("Containers", "Container")
      Description("Colocated Container Model Description")
      Field("id", gorma.UUID, func() {
        PrimaryKey()
        Description("This is the Clc Model PK field")
      })
      BelongsTo("Service")
    })

MohamedFAhmed avatar Jun 30 '16 01:06 MohamedFAhmed

It looks like the definition is off for containers, instead of:

    Attribute("containers", func(){
        ArrayOf(ContainerPayload)
    })

It should be:

    Attribute("containers", ArrayOf(ContainerPayload))

Does the error still occur if you make that change?

raphael avatar Jun 30 '16 04:06 raphael

Thanks for your response Raphael.

Yes we did change it to that and got this error

([design/models.go:61] Unsupported type: 0x8 array in unnamed BuildSource

MohamedFAhmed avatar Jun 30 '16 05:06 MohamedFAhmed

OK this may be a current limitation of gorma, @bketelsen should chime in.

raphael avatar Jun 30 '16 07:06 raphael

can you share your design in a gist or github link? I'd like to replicate this. @MohamedFAhmed

bketelsen avatar Jul 19 '16 16:07 bketelsen

I received the following error, could be related:

[../design/storage.go:35] Unsupported type: 0x6 string in unnamed BuildSource
[../design/storage.go:35] Unsupported type: 0x8 array in unnamed BuildSource
[../design/storage.go:55] Unsupported type: 0x6 string in unnamed BuildSource
[../design/storage.go:76] Unsupported type: 0x8 array in unnamed BuildSource
[../design/storage.go:13] Unsupported type: 0x6 string in unnamed BuildSource

I seem to have resolved it by making sure the "name" of my Types were not the same as the "name" of my Resources. I can put my design files somewhere if you would like.

schmorrison avatar Dec 18 '16 14:12 schmorrison

I use the Any Type in payload ,has Error too ,error:Unsupported type: 0x7 any in unnamed BuildSource delete this,all ok

agui2200 avatar Apr 20 '17 11:04 agui2200

I'm getting Unsupported type: 0x8 array in unnamed BuildSource like @MohamedFAhmed and can share the gist if you like, @bketelsen. You could reproduce the error by defining something simple like Attribute("identifiersArray", ArrayOf(String).

robsliwi avatar Sep 03 '18 13:09 robsliwi