Мне нужно получить все учетные записи @client (has_many :accounts, as: :item
- это отношения). Иметь учетную модель с: полиморфным полем элемента (belongs_to :item, polymorphic: true
, не более), моделью продажи с has_many :accounts
и belongs_to :client
.
Мой запрос:
@accounts = Account.where(company: current_user.company_id).joins(:items).where({ items: { client_id: @client.id } })
и получите следующую ошибку:
Cannot eagerly load the polymorphic association :item
class Sale < ApplicationRecord
belongs_to :user
belongs_to :company
belongs_to :category, required: false
belongs_to :client, required: false
has_many :accounts, as: :item
end
class Client < ApplicationRecord
belongs_to :user
belongs_to :company
belongs_to :category, required: false
has_many :sales
end
class Account < ApplicationRecord
belongs_to :item, polymorphic: true
belongs_to :user
belongs_to :company
end
Ожидается вывод объекта Account со всеми платежами @client.