gobuffalo / buffalo

Rapid Web Development w/ Go
http://gobuffalo.io
MIT License
8.08k stars 578 forks source link

Buffalo g r people generates invalid names #985

Closed paganotoni closed 6 years ago

paganotoni commented 6 years ago

It seems that Buffalo resources generator is not using correct naming in some cases when using irregular plurals as people like:

$ buffalo g r people first_name:string last_name:string email:string identification:string

it:

forrest321 commented 6 years ago

Before generating, locate inflections.json in the root of your buffalo app and add the preferred naming like so:

{ "singular": "plural", "person": "people" }

buffalo build && buffalo test

The generate command will now respect the irregular naming convention as defined in the inflections doc. Pertinent output from my test run:

create templates/people/show.html run buffalo db g model person first_name:string last_name:string email:string identification:string create models/person.go create models/person_test.go

paganotoni commented 6 years ago

Hey, @forrest321 thanks for sharing that! do you know by chance where do we (in which file/line) load those infections in buffalo/inflect? this is very interesting for me and would love to know more.

This sort of common plural/singulars should be part of inflects default dictionary.

forrest321 commented 6 years ago

It looks like the builder first checks to see if an inflections.json file is present in the root folder. If that doesn't work, an empty file is created.

See here: https://github.com/gobuffalo/buffalo/blob/a928a9376ff795d8c93d5b27ded55ec17fe5eb30/buffalo/cmd/build/apkg.go#L23

So, if you have an existing inflections.json file, or can locate a good one, putting it in the root bufffalo folder before building should handle it.

markbates commented 6 years ago

https://github.com/markbates/inflect/blob/b5c853d089b86134926274bc7a98496fee5e1d6b/inflect.go#L649


Mark Bates

On Mar 22, 2018, 3:19 PM -0400, Forrest notifications@github.com, wrote:

It looks like the builder first looks to see if an inflections.json file is present in the root folder. If that doesn't work, an empty file is created. See here: https://github.com/gobuffalo/buffalo/blob/a928a9376ff795d8c93d5b27ded55ec17fe5eb30/buffalo/cmd/build/apkg.go#L23 So, if you have an existing inflections.json file, or can locate a good one, putting it in the root bufffalo folder before building should handle it. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

forrest321 commented 6 years ago

Ah! It is in the default rule set. I'll continue digging, there might be a code issue.

https://github.com/markbates/inflect/blob/b5c853d089b86134926274bc7a98496fee5e1d6b/inflect.go#L243 rs.AddIrregular("person", "people")

forrest321 commented 6 years ago

Working as expected in the v4.2.2 dev branch. After seeing the line noted in my previous comment that specifically adds the person/people rule, I removed the line I created in the inflections.json file and tested again. Files were generated using the "person" & "people" nomenclature.

@paganotoni Have you tried a go get -u ... ?

paganotoni commented 6 years ago

🤔 no, trying that now!

paganotoni commented 6 years ago

@forrest321 go get -u github.com/markbates/inflect ?

forrest321 commented 6 years ago

Oh sorry, go get -u github.com/gobuffalo/buffalo/...

Should update everything, just in case.

paganotoni commented 6 years ago

ok, trying that

paganotoni commented 6 years ago

@forrest321 after updating all, it still happens the same with latest buffalo version

forrest321 commented 6 years ago

Can you post a pastebin with the output? Also any classes you may have created for generation?

paganotoni commented 6 years ago
buffalo g r people first_name:string last_name:string email:string identification:string
      create  actions/people.go
      create  actions/people_test.go
      create  locales/people.en-us.yaml
      create  templates/people/_form.html
      create  templates/people/edit.html
      create  templates/people/index.html
      create  templates/people/new.html
      create  templates/people/show.html
         run  buffalo db g model person first_name:string last_name:string email:string identification:string
v4.3.0

      create  models/person.go
      create  models/person_test.go
         run  goimports -w actions/actions_test.go actions/app.go actions/home.go actions/home_test.go actions/people.go actions/people_test.go actions/render.go grifts/db.go grifts/init.go main.go models/models.go models/models_test.go models/person.go models/person_test.go
> migrations/20180323135845_create_people.up.fizz
> migrations/20180323135845_create_people.down.fizz
         run  goimports -w actions/actions_test.go actions/app.go actions/home.go actions/home_test.go actions/people.go actions/people_test.go actions/render.go grifts/db.go grifts/init.go main.go models/models.go models/models_test.go models/person.go models/person_test.go
forrest321 commented 6 years ago

How about the contents of the generated person.go, please?

paganotoni commented 6 years ago

990 solves the buffalo part of this issue, I'm closing this one and adding model naming issues into another pop model.

vizcay commented 6 years ago

Hi everyone!

@paganotoni how you finally solved this issue? I'm in the exact same spot, I've added the correct inflections to the json file, but the model it is still being generated with inconsistencies (my example is "venta" => "ventas"). After that, the plural of the templates is correctly named but is failing the db part (pop I believe).