ruby-on-rails – Rails有很多错误
发布时间:2020-12-17 02:17:31 所属栏目:百科 来源:网络整理
导读:似乎我已经将源定义为AR错误消息,但仍然会出现错误.任何的想法? Rails 3.2,Ruby 1.9.2 class Document ActiveRecord::Base has_many :participations has_many :users,:through = :participations has_many :editing_sessions has_many :editors,:through =
似乎我已经将源定义为AR错误消息,但仍然会出现错误.任何的想法? Rails 3.2,Ruby 1.9.2
class Document < ActiveRecord::Base has_many :participations has_many :users,:through => :participations has_many :editing_sessions has_many :editors,:through => :editing_sessions,:source => :users end class User < ActiveRecord::Base has_many :participations has_many :documents,:through => :participations has_many :editing_sessions has_many :open_documents,:source => :documents end class EditingSession < ActiveRecord::Base belongs_to :users belongs_to :documents end create_table "editing_sessions",:force => true do |t| t.integer "user_id" t.integer "document_id" t.datetime "created_at",:null => false t.datetime "updated_at",:null => false end Console: u = User.first => ... OK u.editing_sessions => [] u.open_documents => ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :document in model EditingSession. Try 'has_many :open_documents,:source => <name>'. Is it one of :users or :documents? 解决方法
尝试更改EditingSession定义,以便belongs_to标签采用单数形式:
class EditingSession < ActiveRecord::Base belongs_to :user belongs_to :document end 但是以复数形式将其他源定义保留在Document和Users类中(即:source =>:users和:source =>:documents) 这是Ruby on Rails Has-Many-Through Guide的惯例 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – .NET zlib Stream与Actionscript ByteArray.uncompre
- nand flash粗析(二)------NAND flash 读写
- C语言中的线程间通信
- 【最终版】Cocos2d-x&JS v3.7 发布!
- SQLite——只要3分钟,你就可以在.NET上创建和运行它
- c – 哪些贪心的初始化器列表示例潜藏在标准库中?
- 32.读书笔记收获不止Oracle之表链接的驱动顺序
- ios – Storyboard状态栏后面的内容
- what the hell are you doing? SqLite...
- Flex获取参数(二)――FlexGlobals.topLevelApplication