Skip to content

DTOs don't work with inheritance #5

@pboling

Description

@pboling
class SortedQueryDto < ::Castkit::DataObject
  optional do
    string :sort
  end
end

class FilteredSortedQueryDto < SortedQueryDto
  optional do
    string :filter
  end
end

FilteredSortedQueryDto.new(sort: "auto")

When you run that you will get:

irb(main):013> FilteredSortedQueryDto.new(sort: "auto")
/var/home/pboling/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/castkit-0.3.0/lib/castkit/contract/validator.rb:222:in 'Castkit::Contract::Validator#handle_unknown_keys!': Unknown attribute(s): sort (Castkit::ContractError)

The important bits being the source line: lib/castkit/contract/validator.rb:222 and the error:

'Castkit::Contract::Validator#handle_unknown_keys!':
Unknown attribute(s): sort (Castkit::ContractError)

Am I doing something wrong, or is inheritance not supported?

(This example is contrived, and only for illustration; I don't think it is a good idea to build a sorted filter query like this!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions