У меня есть несколько таблиц, которые объединены полиморфной ассоциацией...
Я пытаюсь найти способ сделать одиночный запрос для возврата данных из нескольких этих таблиц...
Мои модели следующие:
#profile.rb
class Profile < ActiveRecord::Base
has_many :user_profiles, dependent: :destroy
has_many :wizards, through: :user_profiles, source: :user, source_type: "Wizard"
end
#user_profile.rb
class UserProfile < ActiveRecord::Base
belongs_to :user, polymorphic: true, dependent: :destroy
belongs_to :profile
end
#wizard.rb
class Wizard < ActiveRecord::Base
has_one :user_profile, as: :user, dependent: :destroy
has_one :profile, through: :user_profile
has_one :wizard_specialization, dependent: :destroy
has_one :career, through: :wizard_specialization
end
#career.rb
class Career < ActiveRecord::Base
has_many :wizard_specializations, dependent: :destroy
has_many :wizards, through: :wizard_specializations
end
Как написать запрос соединения (или :includes
), чтобы вернуть профиль всех мастеров, а также их информацию из таблицы profiles
, а также включить их специализацию из таблицы careers
в таблицу wizard_specializations
?
Заранее спасибо.
PS: будет здорово, если я смогу исключить такие поля, как created_at
и updated_at