Два перехода has_many к одной и той же модели Rails
Модели:
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
Иногда я хочу получить все профили пользователя с помощью интеграций, а иногда - с помощью тегов. Как?
1 ответ
Ответ:
has_many :profiles_tagged, through: :tags, source: :profile
По модели пользователя