rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.07k stars 161 forks source link

Add support for relation.infer_id_from_class setting #661

Closed solnic closed 2 years ago

solnic commented 2 years ago

This makes inferring relation ids from constant names explicitly configurable, which will make things much simpler to handle. This behavior was previously implicit and caused a lot of pain in the code.

You can configure it "globally" within your runtime or on a per-relation class basis.

> runtime = ROM::Runtime.new { |runtime| runtime.config.relation.infer_id_from_class = true }
=> #<ROM::Runtime:0x00007f6d4790bc10..>
irb(main):005:0> class Users < ROM::Relation; end
=> nil
irb(main):006:0> runtime.register_relation(Users)
=> [#<ROM::Components::Relation:0x00007f6d479b2740...]
> runtime.resolver["relations.users"]
=> #<Users name=ROM::Relation::Name(users) dataset=[]>

This can be done relatively easily for other component types too.