修改ActiveRecord::Associations::ClassMethods

修改ActiveRecord::Associations::ClassMethods,class,activerecord,methods,collections,associations,Class,Activerecord,Methods,Collections,Associations,我有一个模型 class Tale < ActiveRecord::Base has_many :tale_culture_joins has_many :cultures, through: :tale_culture_joins, dependent: :destroy, crud: true, index: true has_many :tale_purpose_joins has_many :purposes, through: :tale_purpose

我有一个模型

 class Tale < ActiveRecord::Base
   has_many :tale_culture_joins
   has_many :cultures, through: :tale_culture_joins, dependent: :destroy, crud: true, index: true
   has_many :tale_purpose_joins
   has_many :purposes, through: :tale_purpose_joins, dependent: :destroy, crud: true, index: true
   has_many :tale_book_joins
   has_many :books, through: :tale_book_joins, dependent: :destroy, crud: true, index: true
   has_many :tale_keyword_joins
   has_many :keywords, through: :tale_keyword_joins, dependent: :destroy, crud: true, index: true
   has_many :tale_character_joins
   has_many :characters, through: :tale_character_joins, dependent: :destroy, crud: true, index: true
   has_many :tale_moral_joins
   has_many :morals, through: :tale_moral_joins, dependent: :destroy, crud: true
   has_many :values, through: :morals, index: true
   has_many :tale_event_joins
   has_many :events, through: :tale_event_joins, dependent: :destroy, crud: true

  end
在数据库中进行更改。 我必须做以下几件事

   tale.moral_ids = []
然后

我已经编写了控制器代码-希望将其放在模型本身中。怎么做

此外,我还需要在id上的join_表模型上设置一个默认的_范围,以确保tale.MOTALIS不会按MOTALI_id自动排序返回,而是按join表中的插入顺序返回

如何覆盖/修补/修改此rails行为,以避免发生其他崩溃

我知道集合可能类似于集合和顺序不变量。但是我的应用程序需要排序功能,我不想添加额外的逻辑,而是按照我的顺序进行排序,并直接处理顺序

   tale.moral_ids = []
   tale.moral_ids = [2,1]