'WEBrick run on hanami 1.0.0 shows errors because of wrong inflection

I generated model with hanami generate model stimulus. Then I fixed "stimuluses" to "stimuli" in the migration file name and inside, the table name.

Everytime I load a page I get this error in the server console window:

[ROM::Relation[Stimuluses]] failed to infer schema. Make sure tables exist before ROM container is set up. This may also happen when your migration tasks load ROM container, which is not needed for migrations as only the connection is required (schema parsing returned no columns, table "stimuluses" probably doesn't exist)

I looked into the libraries and found that this functionality has Inflecto library. Then I tried both adding to hanami project this:

# /config/initializers/inflecto.rb
require 'inflecto'

Inflecto.inflections do |inflect|
  inflect.irregular('stimulus', 'stimuli')
end

And editing the defualt library file:

# gems/inflecto-0.0.2/lib/inflecto/defaults.rb
Inflecto.inflections do |inflect|
  ...
  inflect.irregular('stimulus', 'stimuli')
  ...
end

But the message is still there after restarting the server.

Is this something I should solve and if yes, how to do this?

EDIT:

Also tried:

# /config/initializers/inflector.rb
require 'hanami/utils/inflector'

Hanami::Utils::Inflector.inflections do
  exception 'stimulus', 'stimuli'
end


Solution 1:[1]

I'm assuming we are talking about Hanami v1.0.0, right?

You nearly succeeded. What hit you is that initializers seem to be not loaded when executing hanami commands and maybe a bug in code reloading. So instead of an initializer put it into a file that gets loaded when hanami commands are executed or require the initializer file in such a place. E.g.,

# config/initializers/inflections.rb
require 'hanami/utils/inflector'

Hanami::Utils::Inflector.inflections do
  exception 'stimulus', 'stimuli'
end

and then in your environment file

# config/environment.rb
# ...
require_relative 'initializers/inflections.rb'
# ...

I'm not sure if that is a good place to put custom inflection rules, but at least it works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kaikuchn