How in the world do you register a relation. None of the docs that I can find deal with this
Help???
How in the world do you register a relation. None of the docs that I can find deal with this
Help???
Hi @joeradtke, thanks for using Hanami!
Weāll need some more information to help you here. For example:
If you can share a full reproduction of this issue (e.g. a Hanami app using same versions and same ROM setup as you have in your app), that would help us help you.
I should note that Hanami 2 does not currently have dedicated docs about registering ROM relations because Hanami 2 has not yet had a release with a first-party database layer. This is coming soon as part of version 2.2 (we just released a beta), but the final release (and the full set of corresponding docs) will be a month or two away.
Hanami 2.1
Hanami.app.register_provider :persistence, namespace: true do
prepare do
require āromā
require ārom-changesetā
require ārom/coreā
require ārom/sqlā
config = ROM::Configuration.new(:sql, target[āsettingsā].database_url)
config.relation(:users)
register āconfigā, config
register ādbā, config.gateways[:default].connection
end
start do
config = target[āpersistence.configā]
config.auto_registration(
target.root.join(ālib/trial3/persistenceā),
namespace: āTrial3::Persistenceā
)
register āromā, ROM.container(config)
end
end
[
Hanami Mastery - https://hanamimastery.com
Hanami 2.0 comes without the persistence layer nor views preconfigured. It is useful then to know how to set up ā¦
](Configure ROM from scratch | Hanami Mastery)
relation files in lib/appname/persistence/relations
After another day of experimenting I finally got it to work but Iām not sure what I did.
Thereās a steep learning curve with hanami but Iām getting there. Itās a challenge but quite satisfying.
Joe
Welcome, @joeradtke
I believe this might be the problem. You can either automatically register relations by convention, or you can manually register them, but you have to choose one or the other.
config.relation
is for manual registration, such as:
config.relation :users do
schema :users, infer: true
end
Whereas, later in your example you have
This indicates to me that you should have class-based relations located in `lib/trial3/persistenceā
# lib/trial3/persistence/relations/users.rb
module Trial3
module Persistence
module Relations
class Users < ROM::Relation[:sql]
schema :users, infer: true
end
end
end
end
I suggest removing config.relation(:users)
and seeing if that helps, however I will echo Timās advice and say that the 2.2 release will make this substantially easier to setup.
Actually adding config.relation(:users) is what fixed it.
Its a rough road but Iām slowly progressing.
| alassek
July 22 |
- | - |
Welcome, @joeradtke
joeradtke:
config.relation(:users)
I believe this might be the problem. You can either automatically register relations by convention, or you can manually register them, but you have to choose one or the other.
config.relation
is for manual registration, such as:
config.relation :users do
schema :users, infer: true
end
Whereas, later in your example you have
joeradtke:
config.auto_registration(
target.root.join(ālib/trial3/persistenceā),
namespace: āTrial3::Persistenceā
)
This indicates to me that you should have class-based relations located in `lib/trial3/persistenceā
# lib/trial3/persistence/users.rb
module Trial3
module Persistence
class Users < ROM::Relation[:sql]
schema :users, infer: true
end
end
end
I suggest removing config.relation(:users)
and seeing if that helps, however I will echo Timās advice and say that the 2.2 release will make this substantially easier to setup.
@joeradtke Yeah, after 2.2 release Iāll also launch more up to date tutorial series on HanamiMastery, I hope the overall experience will be on the next-level and whole configuration will be significantly easier.
Thanks for bringing it in!
Iām looking forward to it