Project、MonthlySubscription(Subscription)、MonthlyTransactionQueue(TransactionQueueのsti)の3つのモデルがあります。サブスクリプションとTransactionQueueの両方belong_to
プロジェクト。ActiveRecordを使用した1つのモデルのスナップショット
MonthlySubscriptionのコピーを作成し、Release.released = falseを持つプロジェクトのMonthlyTransactionQueueに配置します。私はARを使ってどのようにこれを行いますか?
私のSQLは次のようになります。ARについては
insert into transaction_queues
select a.*, b.id as release_id
from subscriptions a
left join releases b
on a.project_id = b.project_id
where b.released = false
and a.type = 'ReleaseSubscription'
が、私はこのReleaseSubscription.joins(project: :releases)
を開始しているが、それはあなたがいくつかのオプションがありますRelease.releasedフィールド
ありがとうございます。 'MonthlySubscription.where(リリース:偽)'では、リリースされたフィールドはリリースモデルにあるので、 'MonthlySubscription.joins(Release.where(released:false))'のようなものが必要でしょうか? – Adam12344
'MonthlySubscription.where(released:false).each do | sub |を置き換えます。 ':' MonthlySubscription.joins(:releases).where(リリース:{リリース:偽})。each do | sub | ' – isaacsloan