我已经为连接构建了查询,但我不知道如何构建仅检查关联的最后一条记录的部分。
stream = 1..10 |> ParallelStream.map(fn i -> i * 2 end)
stream |> Enum.into([])
[2,4,6,8,10,12,14,16,18,20]
Job.where('balance != 0').joins(:ledgers).to_sql
对其余部分进行伪编码:
=> "SELECT \"jobs\".* FROM \"jobs\" INNER JOIN \"ledger_entries\" ON \"ledger_entries\".\"job_id\" = \"jobs\".\"id\" AND \"ledger_entries\".\"type\" IN ('LedgerEntry::JobAccount') WHERE \"jobs\".\"deleted_at\" IS NULL AND (balance != 0)"