Как мы получаем счета за определенный месяц в зависимости от клиентов с учетом ассоциаций - PullRequest
0 голосов
/ 26 апреля 2020

Как мы получаем некоторые столбцы для каждой таблицы: - например, имя клиента, имя подписки, даты использования, информация о счетах.

Клиент:

has_many :subscriptions, class_name: 'CustomerSubscription'
has_many :azure_utilizations, through: :subscriptions
has_many :azure_monthly_bills, through: :subscriptions

Ежемесячные счета:

belongs_to :customer_subscription
has_one :customer_account, through: :customer_subscription
has_and_belongs_to_many :azure_utilizations, {
    class_name: 'Api::Utilization',
    foreign_key: 'azure_monthly_bill_id',
    association_foreign_key: 'azure_utilization_id',
    join_table: 'azure_monthly_bill_items'
  }

Использование:

belongs_to :customer_subscription
has_one :customer_account, through: :customer_subscription
has_and_belongs_to_many :azure_monthly_bills, {
    class_name: 'Api::MonthlyBill',
    foreign_key: 'azure_utilization_id',
    association_foreign_key: 'azure_monthly_bill_id',
    join_table: 'azure_monthly_bill_items'
  }

Подписка:

belongs_to :customer_account
  with_options dependent: :destroy do
    has_many :stopped_resources
    has_many :azure_utilizations, class_name: 'Api::Utilization'
    has_many :azure_monthly_bills, class_name: 'Api::MonthlyBill'
  end

Наиболее ценится, если кто-либо отправит запрос, где мы получаем конкретный месяц month_bills и использования на основе подписок клиентов.

Я пробовал запрос ниже, но все еще не получил никакого результата: -

CustomerAccount.last.subscriptions
               .select(:name,:joins=>"JOIN azure_monthly_bills ON azure_monthly_bills.customer_subscription_id = customer_subscriptions.id      JOIN azure_utilizations    ON azure_utilizations.customer_subscription_id = customer_subscriptions.id", :conditions=>"azure_monthly_bills.month = '3' AND azure_monthly_bills.year = '2020'")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...