型号:
class User < ActiveRecord::Base
has_many :reports
has_many :social_accounts
has_one :api_client
has_many :integrations
has_many :profiles, through: :integrations
has_many :tags
has_many :profiles, through: :tags
end
class Tag < ActiveRecord::Base
belongs_to :user
belongs_to :profile
end
class Profile < ActiveRecord::Base
has_many :integration_profiles
has_many :integrations, through: :integration_profiles
has_many :users, through: :integrations
belongs_to :api_client
has_many :tags
ene
有时我想通过集成检索所有用户的配置文件,有时我想通过标签检索。怎么样?
答案 0 :(得分:-1)
答案:
has_many :profiles_tagged, through: :tags, source: :profile
在用户模型
上