导轨错误:对象不支持#inspect [英] Rails error: object does not support #inspect

查看:347
本文介绍了导轨错误:对象不支持#inspect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抓我的头在这里...如果我尝试使用Rails以下内容:

Scratching my head here... If I try the following with rails:

User.limit(25).includes([:addresses])

我得到:

 User Load (109.5ms)  EXEC sp_executesql N'SELECT TOP (25) [User].* FROM [User]'
 Address Load (112.3ms)  EXEC sp_executesql N'SELECT [Address].* FROM [Address] WHERE [Address].[UserId] IN (N''1'', N''2'', N''3'', N''6'', N''7'', N''8'', N''9'', N''11'', N''12'', N''16'', N''17'', N''18'', N''19'', N''20'', N''21'', N''22'', N''24'', N''25'', N''26'', N''27'', N''28'', N''29'', N''30'', N''31'', N''34'')'
(Object doesn't support #inspect)
 =>  

如果我不是做

@users = User.limit(25).joins([:addresses])

这工作得很好,但内部联接是不是我想要的不提,我其实是想通过sunspot_rails只支持包含做到这一点。

this works fine, however an inner join is not what I want not to mention I'm actually trying to do this through sunspot_rails which only supports includes.

我不完全知道什么是了这个错误。我怀疑这可能是由于这样的事实,这是一个传统的MSSQL数据库这样的命名规则是远远不能满足轨道喜欢。不过我无所适从至于具体是什么问题。

I'm not entirely sure what is up with this error. I suspect it might be due to the fact that this is a legacy MSSQL database so the naming conventions are nowhere near what rails likes. However I'm at a loss as to what the specific issue is.

该型号如下,精简到验证重现该问题的最小值:

The models are as follows, stripped down to the minimum which is verified to reproduce the problem:

class User < ActiveRecord::Base
  set_table_name "User"
  set_primary_key "ID"

  has_many :addresses, :foreign_key => 'UserId'
end

class Address < ActiveRecord::Base
  set_table_name "Address"
  set_primary_key "ID"
  belongs_to :user
end

这就是它。另外,对搜索和验证用户模型等code,但我已经评论说,所有出并验证它在这个问题上没有任何影响。我坚持这一点,任何帮助是AP preciated。该应用程序是使用Rails 3.1,用ActiveRecord - SQLSERVER适配器和tiny_tds。

That is it. There is other code on the user model for searching and authentication, but I've commented that all out and verified it has no impact on this problem. I'm stuck on this, any help is appreciated. The app is using rails 3.1, with activerecord-sqlserver-adapter and tiny_tds.

推荐答案

解决...

:foreign_key =>用户名,而不是:foreign_key =>用户ID

:foreign_key => "UserID", not :foreign_key => "UserId"

由于某些原因,在不同的情况下,似乎并没有做非预先加载的时候,还是有.joins打扰轨,但确实有.includes。卫生署。

For some reason, the case difference does not seem to bother rails when doing non eager loading, or with .joins, but does with .includes. Doh.

这篇关于导轨错误:对象不支持#inspect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆