rom-rb / rom-mongo

(Looking for a maintainer) MongoDB support for rom-rb
https://rom-rb.org
MIT License
33 stars 21 forks source link

Feature/rom 5 0 #30

Open alex-lairan opened 5 years ago

alex-lairan commented 5 years ago

Hi @solnic

I tried to make spec pass, but I have troubles with Dry::Struct :

     Dry::Struct::Error:
       [ROM::Struct::User.new] :_id is missing in Hash input

I think I'm not using it well

      schema do
        # TODO: we need ROM::Mongo::Types (similar to ROM::SQL::Types)
        attribute :_id, ROM::Types.Nominal(BSON::ObjectId)
        attribute :name, ROM::Types::String
        attribute :email, ROM::Types::String
      end

Any idea ?

solnic commented 5 years ago

Does it coerce key names to symbols?

alex-lairan commented 5 years ago

How to verify ?

I thought that transform_keys(&:to_sym) should to the job.

solnic commented 5 years ago

It does not look like this custom struct class is used. Regardless, structs should not be used for coercing keys. We have Relation#output_schema for this, as I mentioned - see how rom-elasticsearch is structured and mimic it here. We need a custom schema class configured and then you can do this.