lib/rom/repository/struct_builder.rb in rom-repository-1.0.2 vs lib/rom/repository/struct_builder.rb in rom-repository-1.1.0

- old
+ new

@@ -38,15 +38,22 @@ def visit_relation(node) relation_name, meta, header = node name = meta[:combine_name] || relation_name.relation - model = call(name, header) + model = meta.fetch(:model) { call(name, header) } + member = + if model < Dry::Struct + model + else + Dry::Types::Definition.new(model).constructor(&model.method(:new)) + end + if meta[:combine_type] == :many - [name, Types::Array.member(model)] + [name, Types::Array.member(member)] else - [name, model.optional] + [name, member.optional] end end def visit_attribute(attr) [attr.aliased? && !attr.wrapped? ? attr.alias : attr.name, attr.to_read_type]