我的网站上的每个用户都有一个列表,该列表由不同类型的用户组成。我使用has_many直通关系来完成此操作,如下所示:
List.rb:
class List < ActiveRecord::Base
belongs_to :company
has_many :list_applicants
has_many :applicants, through: :list_applicants
endApplicant.rb:
class Applicant < ActiveRecord::Base
has_many :list_applicants
has_many :lists, through: :list_applicants
endListApplicant.rb
class ListApplicant < ActiveRecord::Base
attr_accessible :applicant_id, :list_id
belongs_to :applicant
belongs_to :list
endCompany.rb:
class Company < ActiveRecord::Base
has_one :list
end当一个用户将另一个用户添加到他们的列表中时,我想记录添加该用户的日期,这样他们就可以根据添加的日期对他们的用户列表进行排序。做这件事最好的方法是什么?
发布于 2012-11-27 16:23:53
您可以使用ListApplicant模型的created_at字段(如果有)。如果没有,您可以手动添加类似的字段。
更新:
您可以通过指定申请者和列表来访问该字段,如下所示:
@applicant.list_applicants.where(list_id: @list.id).first.created_athttps://stackoverflow.com/questions/13579967
复制相似问题