Here is a complete example of rail models for those who want to see them.
It took me a couple of hours to understand, so I decided to share with the whole world
This assumes that you have one model with a name RssFeedand another with a name RssFeedUserthat is the connection model for has_many: through for the model with the nameUser
RssFeed.find_by_sql(
RssFeed
.arel_table
.join(RssFeedUser.arel_table, Arel::Nodes::OuterJoin)
.on(RssFeed.arel_table[:id].eq(RssFeedUser.arel_table[:rss_feed_id]))
.where(RssFeedUser.arel_table[:user_id].eq(nil))
.project('rss_feeds.*')
)
source
share