[英]RubyMine error: Unable to find associated Rails Model for ':users' associations failed
I'm working on some tutorial and i'm having some problems.我正在编写一些教程,但遇到了一些问题。 RubyMine can't find associated Rails Model for ':users' associations failed RubyMine 找不到“:用户”关联的关联 Rails 模型失败
I'm using:我在用着:
- RubyMine 7 - 红宝石矿 7
- Ruby version meneger (rvm) - Ruby 版本 meneger (rvm)
- ruby-1.9.3-p551 [ x86_64 ] - ruby-1.9.3-p551 [x86_64]
- ruby-2.1.5 [ x86_64 ] - ruby-2.1.5 [x86_64]
- rails Rails 4.1.8 - 导轨导轨 4.1.8
- Gem sqllite3 - 宝石 sqllite3
My models are:我的模型是:
class Company < ActiveRecord::Base
has_many :users
has_many :projects
end
class Project < ActiveRecord::Base
belongs_to :company
has_many :works
has_many :users, :through => :works
end
class User < ActiveRecord::Base
belongs_to :company
has_many :works
has_many :projects, :through => :works
end
class Work < ActiveRecord::Base
belongs_to :project
belongs_to :user
end
Shema.rb谢玛.rb
ActiveRecord::Schema.define(version: 20141207111312) do
create_table "companies", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "projects", force: true do |t|
t.string "name"
t.integer "company_id"
t.integer "default_rate"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: true do |t|
t.string "fname"
t.string "lname"
t.integer "company_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
add_index "users", ["user_id"], name: "index_users_on_user_id"
create_table "works", force: true do |t|
t.integer "project_id"
t.integer "user_id"
t.datetime "datetimeperformed"
t.decimal "hours", precision: 5, scale: 2
t.datetime "created_at"
t.datetime "updated_at"
end
end
Is there something wrong with my code or is this some wrong RubyMine configuration?我的代码有问题还是 RubyMine 配置有问题?
UPDATE:更新:
Problem is the same if i use Mysql2 or sqllite3 gem如果我使用 Mysql2 或 sqllite3 gem,问题是一样的
这是一个常见的 RubyMine 错误,通常可以通过运行File / Invalidate Caches...来解决。
Looks like the problem is in RubyMine editor (bug)!看起来问题出在 RubyMine 编辑器中(错误)! If you run your application let's say on ruby-2.1.5 and you change you RubyMine setting (Ruby SDK and gems) to some other version and then change back to ruby-2.1.5 version, you will get this error.如果您在 ruby-2.1.5 上运行您的应用程序并将您的 RubyMine 设置(Ruby SDK 和 gems)更改为其他版本,然后再更改回 ruby-2.1.5 版本,您将收到此错误。
Quick fix is that you create a new project and copy paste those files there快速修复是您创建一个新项目并将这些文件复制粘贴到那里
Its all saying that its not found the referential fields which are required to form users association on the current model.都说它没有找到在当前模型上形成用户关联所需的引用字段。
So you better check, if you already added the columns to reference users to those tables or if you already did that, try recheck once again, if you run the migration to make the changes done on database.因此,您最好检查一下,如果您已经添加了列以将用户引用到这些表中,或者您已经这样做了,请再次尝试重新检查,如果您运行迁移以对数据库进行更改。
# example
add_reference :users, :company, index: true
or generate the following migration:或生成以下迁移:
rails g migration AddCompanyRefToUsers user:references
On other side, it could be rubymine's caching problem.另一方面,它可能是 rubymine 的缓存问题。 # I am not sure # 我不知道
Reference:http://edgeguides.rubyonrails.org/active_record_migrations.html参考:http ://edgeguides.rubyonrails.org/active_record_migrations.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.