我在activity_summaries
和gears
之间存在“n到n”关系。
#ActivitySummary
has_many :activity_summaries_gears
has_many :gear_furnished, -> { where(activity_summaries_gears: {furnished: true}) }, through: :activity_summaries_gear, source: :gear
has_many :gear_advised, -> { where(activity_summaries_gears: {furnished: false}) }, through: :activity_summaries_gear, source: :gear
#active_summaries/_form
<%= check_box_tag 'activity_summary[gear_furnished_ids][]', gear.id,
@execution_summary.gear_furnished.include?(gear) %>
<%= check_box_tag 'activity_summary[gear_advised_ids][]', gear.id,
@execution_summary.gear_advised.include?(gear) %>
我的关系表有一个额外的栏目。
如果关联是使用furnished
创建的,我想将gear_furnished
设置为true;如果使用gear_advised
创建关联,则设置为false。
我在ActivitySummary
控制器中使用数组furnished_gear_ids
和数组advised_gear_ids
创建关系。