Hanami has_many关联错误(在1.1.0.beta1中)

时间:2017-09-25 17:42:13

标签: hanami hanami-model

我正在使用Hanami 1.1.0.beta1(因为我需要关联)。

event可以有多个actions

class EventRepository < Hanami::Repository
  associations do
    has_many :actions
    ...
  end

class ActionRepository < Hanami::Repository
  associations do
    ...
    belongs_to :event
  end

当我调用此EventRepository方法时:

  def add_action(event, data)
    assoc(:actions, event).add(data)
  end

我收到此错误:

  KeyError:
    key not found: :id
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/model/associations/has_many.rb:195:in `fetch'
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/model/associations/has_many.rb:195:in `_build_scope'
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/model/associations/has_many.rb:47:in `initialize'
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/model/association.rb:20:in `new'
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/model/association.rb:20:in `build'
  # /home/eric/.gem/ruby/2.3.4/gems/hanami-model-1.1.0.beta1/lib/hanami/repository.rb:472:in `assoc'
  ...

我查看了has_many.rb。在initialize我看到subject是一个Event对象,它有一个idHasMany::initialize - subject: #<Event:0x00558f3c198ce8 @id=705, @attributes={:title=>"test_title"}>

但在_build_scope subject已更改为attributes哈希,因此key not found: :id错误。

  

HasMany :: _ build_scope - subject:{:title =&gt;“test_title”}

这很奇怪,因为我看不到subjectinitialize之间_build_scope发生变化的地方......

这是一个错误是1.1.0.beta1,还是我做错了什么?

0 个答案:

没有答案