我正在做以下查询
PortfolioDistribution.joins(:portfolio_distribution_split).
select('policy_number, reinvestment_date, reinvestment_units,
reinvestment_units, split_name, split_percentage').
where(:policy_number => policy_no, :reinvestment_date => period,
:ods_psgamas_gls_portfolio_distribution_split => { :split_name => type })
它返回 15 条记录,但关联的模型portfolio_distribution_split
是nil
. 如果我更改查询以包含关联模型,如下所示:
PortfolioDistribution.joins(:portfolio_distribution_split).
select('policy_number, reinvestment_date, reinvestment_units,
reinvestment_units, split_name, split_percentage').
where(:policy_number => policy_no, :reinvestment_date => period,
:ods_psgamas_gls_portfolio_distribution_split => { :split_name => type }).
includes(:portfolio_distribution_split)
我只得到3条记录?如果我生成SQL
并直接针对数据库运行它,我会得到 15 条记录。其他 12 条记录怎么了?
- 活动模型(3.2.13)
- 活动记录(3.2.13)
- activerecord-sqlserver-适配器 (3.2.8)
- 活动资源 (3.2.13)
- 积极支持 (3.2.13)