Rails includes with scope

后端 未结 4 739
耶瑟儿~
耶瑟儿~ 2021-02-05 01:30

I have a model called Author. An author has many Articles. Articles have a scope called .published that does: where(published: true).

I want to load the author, with the

4条回答
  •  别那么骄傲
    2021-02-05 02:02

    Try this code:

    Author
      .includes(:articles).where(published: true).references(:articles)
      .find(params[:author_id])
    

    Here you can find more information about the example above: includes api doc

提交回复
热议问题