是否可以连接两个表并计算两者的关系数?理想的输出是 [name, recommendation_count, review_count]
Rails has_many多次连接记录数
class PatientProfile
has_many :reviews
has_many :recommendations
# this works
PatientProfile.joins(:reviews).group(:id).pluck(:name, 'count(reviews.id)')
# this does not work
PatientProfile.joins(:recommendations, :reviews).group(:id).pluck(:name, 'count(recommendations.id)', 'count(reviews.id)')
第二个例子为列
你能提供有关您的模型/关系的细节? – archana
@archana增加了更多关于模型的信息 – user2954587
你的'has_many:through'关系在哪里? – archana