问题描述
的SQLite3 ::的SQLException:没有这样的列:organizations.user_id:选择组织* FROM组织WHERE组织,user_ID的= 2
我已经安装我的模型是这样的:
I have setup my models like this:
网友:
用户的has_many:组织
组织:
attr_accessible :name, :founder, :founder_id
belongs_to :founder, :class_name => 'User'
模式:
create_table "organizations", :force => true do |t|
t.string "name"
t.integer "founder_id"
当我去编辑轨管理员用户,我得到这个消息:
When I go to edit a user in rails-admin, I get this message:
`SQLite3::SQLException: no such column: organizations.user_id: SELECT "organizations".* FROM "organizations" WHERE "organizations"."user_id" = 2`
我要访问方正在组织,其中,方正是一个用户。它看起来像 rails_admin
查找USER_ID时,应该寻找一个创始人。
I want to access Founder on Organization, where a Founder is a User.It looks like rails_admin
looks for the user_id when it should be looking for a Founder.
previous问:Can的参考接入_id对象,但不是对象直接
Previous q:Can access _id of a references object but not the object directly
推荐答案
您需要指定用户获取组织的时候,像这样使用的列:
You need to specify which column to use when retrieving organizations from User, like this:
class User < ActiveRecord::Base
has_many :organizations, foreign_key: :founder_id
#...
end
这篇关于没有这样的列有belongs_to的关系将class_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!