@@ -66,6 +66,11 @@ def self.registry
66
66
# @return [Cache] local cache instance
67
67
option :cache , default : -> { Cache . new }
68
68
69
+ # @!attribute [r] inflector
70
+ # @return [Dry::Inflector] String inflector
71
+ # @api private
72
+ option :inflector , default : -> { Inflector }
73
+
69
74
# Return a specific command type for a given adapter and relation AST
70
75
#
71
76
# This class holds its own registry where all generated commands are being
@@ -102,7 +107,8 @@ def call(*args)
102
107
command = ROM ::Commands ::Graph . build ( registry , graph_opts )
103
108
104
109
if command . graph?
105
- CommandProxy . new ( command )
110
+ root = inflector . singularize ( command . name . relation ) . to_sym
111
+ CommandProxy . new ( command , root )
106
112
elsif command . lazy?
107
113
command . unwrap
108
114
else
@@ -114,7 +120,7 @@ def call(*args)
114
120
115
121
# @api private
116
122
def type
117
- @_type ||= Commands . const_get ( Inflector . classify ( id ) ) [ adapter ]
123
+ @_type ||= Commands . const_get ( inflector . classify ( id ) ) [ adapter ]
118
124
rescue NameError
119
125
nil
120
126
end
@@ -139,7 +145,7 @@ def visit_relation(node, parent_relation = nil)
139
145
if meta [ :combine_type ] == :many
140
146
name
141
147
else
142
- { Inflector . singularize ( name ) . to_sym => name }
148
+ { inflector . singularize ( name ) . to_sym => name }
143
149
end
144
150
145
151
mapping =
@@ -190,7 +196,7 @@ def visit_attribute(*_args)
190
196
def register_command ( rel_name , type , rel_meta , parent_relation = nil )
191
197
relation = relations [ rel_name ]
192
198
193
- type . create_class ( rel_name , type ) do |klass |
199
+ type . create_class ( rel_name , type , inflector : inflector ) do |klass |
194
200
klass . result ( rel_meta . fetch ( :combine_type , result ) )
195
201
196
202
meta . each do |name , value |
@@ -237,7 +243,7 @@ def setup_associates(klass, relation, _meta, parent_relation)
237
243
if relation . associations . key? ( parent_relation )
238
244
parent_relation
239
245
else
240
- singular_name = Inflector . singularize ( parent_relation ) . to_sym
246
+ singular_name = inflector . singularize ( parent_relation ) . to_sym
241
247
singular_name if relation . associations . key? ( singular_name )
242
248
end
243
249
0 commit comments