【发布时间】:2016-04-06 01:42:09
【问题描述】:
用户和活动与职业有多对多关联。我想将与用户的职业关联更改为多对一。如何修改?
用户
has_many :common_occupations, :as => :profession
has_many :occupations, :through => :common_occupations
职业
class Occupation < ActiveRecord::Base
has_many :users, :through => :common_occupations, :source => :profession, :source_type => "User"
has_many :campaigns, :through => :common_occupations, :source => :profession, :source_type => "Campaign"
has_many :common_occupations
广告系列
has_many :common_occupations, :as => :profession
has_many :occupations, :through => :common_occupations
普通职业
belongs_to :occupation
belongs_to :profession, :polymorphic => true
【问题讨论】:
标签: ruby-on-rails ruby activerecord ruby-on-rails-3.2