Closed paganotoni closed 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
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.
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.
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.
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.
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")
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 ... ?
🤔 no, trying that now!
@forrest321 go get -u github.com/markbates/inflect ?
Oh sorry,
go get -u github.com/gobuffalo/buffalo/...
Should update everything, just in case.
ok, trying that
@forrest321 after updating all, it still happens the same with latest buffalo version
Can you post a pastebin with the output? Also any classes you may have created for generation?
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
How about the contents of the generated person.go, please?
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).
It seems that Buffalo resources generator is not using correct naming in some cases when using irregular plurals as people like:
it:
Persons
as the plural inperson.go
model.templates/persons/*.html
template instead oftemplates/people/*.html