我网站上的每个用户都有一个列表,其中包含不同类型的用户。我正在使用 has_many through 关系来执行此操作,如下所示:
List.rb:
class List < ActiveRecord::Base
belongs_to :company
has_many :list_applicants
has_many :applicants, through: :list_applicants
end
申请人.rb:
class Applicant < ActiveRecord::Base
has_many :list_applicants
has_many :lists, through: :list_applicants
end
ListApplicant.rb
class ListApplicant < ActiveRecord::Base
attr_accessible :applicant_id, :list_id
belongs_to :applicant
belongs_to :list
end
公司.rb:
class Company < ActiveRecord::Base
has_one :list
end
当用户将另一个用户添加到他们的列表中时,我想记录添加用户的日期,以便他们可以按添加日期对用户列表进行排序。做这个的最好方式是什么?