即使我的查询成功,我也没有遇到任何方法错误

时间:2016-11-15 04:30:28

标签: ruby-on-rails ruby api associations

我在用户和帐户之间有关联。

class User < HerModel
. . .
has_many :accounts
. . .
end


class Account < HerModel
. . .
belongs_to :user
. . .
end

当我尝试查询

def show
user = User.find(params[:id])
accounts = user.accounts

render json: accounts, status: :ok
end

我收到此错误

  

NoMethodError:#Account的未定义方法`each':0x007ff0d384a6e0。

如果user.account.all我可以看到里面的数据是

#<Her::Model::Associations::HasManyAssociation:0x007ffb388c8f80
 @cached_result= #<Account(account) accounts=[{"id"=>551, "user_id"=>127, ... ]#>

文档是如此清晰,但我不知道为什么它在进行关联时不起作用。

我已经在我的连接应用程序中检查了查询是否成功但是当它在应用程序中收到时她总是会触发此错误。有什么想法吗?

更新

{"id": 0, "trace": "her (0.8.2) lib/her/model/attributes.rb:84:in `method_missing'"},
{"id": 1, "trace": "activemodel (5.0.0.1) lib/active_model/attribute_methods.rb:433:in `method_missing'"},
{"id": 2, "trace": "her (0.8.2) lib/her/model/associations/has_many_association.rb:88:in `block in fetch'"},
{"id": 3, "trace": "her (0.8.2) lib/her/model/associations/has_many_association.rb:86:in `tap'"},
{"id": 4, "trace": "her (0.8.2) lib/her/model/associations/has_many_association.rb:86:in `fetch'"},
{"id": 5, "trace": "her (0.8.2) lib/her/model/associations/association_proxy.rb:11:in `kind_of?'"},
{"id": 6, "trace": "her (0.8.2) lib/her/model/associations/association_proxy.rb:39:in `method_missing'"},
{"id": 7, "trace": "actionpack (5.0.0.1) lib/action_controller/metal/renderers.rb:159:in `block in <module:Renderers>'"},
{"id": 8, "trace": "actionpack (5.0.0.1) lib/action_controller/metal/renderers.rb:152:in `block in _render_to_body_with_renderer'"}

我无法粘贴所有内容,但这是上层框架跟踪。

0 个答案:

没有答案