hanami / model

Ruby persistence framework with entities and repositories

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError Exception: can't convert ROM::Relation::Loaded into Hash

rafaels88 opened this issue · comments

When using Hanami 0.9 I use to implement query for some objects combining some relations (as described here http://rom-rb.org/learn/advanced/combine/ ) doing:

my_entities.combine(:relation_one, :relation_two).call

and everything was fine. But now, after upgrading to 1.0 I am having this error:

TypeError Exception: can't convert ROM::Relation::Loaded into Hash

It seems that the new implementation on Hanami::Model::Sql::Entity#call is not handling this anymore. Following below more details of the stacktrace:

TypeError: can't convert ROM::Relation::Loaded into Hash

/Users/rafaelsoares/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/dry-types-0.11.1/lib/dry/types/constructor.rb:47:in `Hash'
/Users/rafaelsoares/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/dry-types-0.11.1/lib/dry/types/constructor.rb:47:in `[]'
/Users/rafaelsoares/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/dry-types-0.11.1/lib/dry/types/constructor.rb:47:in `call'
/Users/rafaelsoares/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/hanami-model-1.0.2/lib/hanami/model/sql/entity/schema.rb:50:in `call'
/Users/rafaelsoares/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/hanami-model-1.0.2/lib/hanami/entity.rb:123:in `initialize'

Maybe there is another better way to do this?

I just figured it out that I can do:

aggregate(:relation_one, :relation_two).call

instead of using #combine. But anyway, since it is a public method and it used to work with Hanami 0.9, I still think it could be an issue.

@flash-gordon hey! Do you have any ideas? 😊

@rafaels88 Thanks for reporting this issue, and I'm sorry about the poor experience.

I don't see it as a public API problem as below 1.0. According to SemVer 2.0, public API can break backward compatibility until 1.0.

@jodosha good point! Agreed, thanks for the answer!