How to do joins on subqueries in AREL within Rails

前端 未结 2 1032
别那么骄傲
别那么骄傲 2021-02-14 16:29

I have a simple model

class User
    has_many :logs


class Logs

related in the usual way through the foreign key logs.user_id. I\'m trying to

2条回答
  •  醉话见心
    2021-02-14 17:11

    You can use join_sources to retrieve the Arel::Nodes::Join from the instance of Arel::SelectManager, and pass that to joins

    Using your example:

    l_t.joins(counts.join_sources).on(l_t[:id].eq(counts[:user_id]))
    

提交回复
热议问题