ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.68k stars 386 forks source link

Help with using FileRepeater #252

Closed egaba closed 6 years ago

egaba commented 6 years ago

I'm trying to create an array of photos. Using the "Review" generator example, the command I'm using to generate is: ponzu generate content review title:"string" author:"string" rating:"float64" body:"string":richtext website_url:"string" items:"[]string" photo:"[]string":file

When running ponzu build && ponzu run, i see the error:

Error decoding json while sorting Review : json: cannot unmarshal string into Go struct field Review.photo of type []string

Although there's an error, I'm still able to start up the server. I upload two different photos, and see only one photo in the response:

{
    "data": [
        {
            "uuid": "03d16f84-bfab-4bb2-a69f-631c609f7422",
            "id": 1,
            "slug": "review-03d16f84-bfab-4bb2-a69f-631c609f7422",
            "timestamp": 1526775027000,
            "updated": 1526777247315,
            "title": "A review",
            "author": "egaba",
            "rating": 0,
            "body": "",
            "website_url": "",
            "items": [],
            "photo": "/api/uploads/2018/05/excited.gif"
        }
    ]
}

I expected photo to be an array like items. What's the correct way to generate an array of files?

nilslice commented 6 years ago

Had you perhaps initially used a non-slice type for the field prior and re-used the same database?

If it's not important data, try deleting the system.db file in your repo (you'll need to re-initialize the CMS with a user and login. Then re-run the server and try to add / view data.

There is currently no "migration" step for ponzu databases, which makes it a little difficult if you need to change the underlying type of a struct field.

egaba commented 6 years ago

Had you perhaps initially used a non-slice type for the field prior and re-used the same database?

This was true. I deleted my system.db and content/review.go files, then re-ran the generation command and it fixed the issue. Thank you again!

nilslice commented 6 years ago

Glad to hear it! Btw, your existing generated code would have worked. No need to re-generate it if your content types didn't change after you deleted the DB.