I am running Ruby on Rails 3.1. I am querying the database in order to retrieve article objects that have not category relationship with a user and I am trying to improve the following code:
article_relationship_ids =
User.article_category_relationships
.uniq_by{|article_category_relationship| article_category_relationship.article_id}
.map(&:article_id)
user.articles.where("articles.id NOT IN (?)", article_relationship_ids)
How can I improve the above code?
P.S.: Is my “retrieving approach” “logically” correct to make what I would like?
This should fetch your ids without further processing on the ruby side: