Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:08:26+00:00 2026-06-03T01:08:26+00:00

I have the following scope in a Rails model. class Suggestion < ActiveRecord::Base has_many

  • 0

I have the following scope in a Rails model.

class Suggestion < ActiveRecord::Base
  has_many :favourites

  def self.favoured_by(user)
    joins(:favourites).where(favourites: { user_id: user.id })
  end
end

That works perfectly. It will return all the suggestions which a particular user has favourited.

How can I retrieve all the suggestions which are either not favourited at all or which are favourited but not by this particular user?

def self.not_favoured_by(user)
  # ...
end

My Favourite model looks like this:

class Favourite < ActiveRecord::Base
  belongs_to :suggestion
  belongs_to :user
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:08:27+00:00Added an answer on June 3, 2026 at 1:08 am
    favorited_suggestions_ids = joins(:favourites).where(favourites: { user_id: user.id }).map(&:id)
    return scoped if favorited_suggestion_ids.empty?
    where('id not in (?)',favorited_suggestions_ids)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the following model: payment.rb: class Payment < ActiveRecord::Base has_many :currencies default_scope :include
I have the following models in my Rails application: class Shift < ActiveRecord::Base has_many
I have the following rails model: class Customer < ActiveRecord::Base attr_accessible :firstname, :lastname, :email,
I have the following associations: class User < ActiveRecord::Base has_and_belongs_to_many :brands, :join_table => 'brands_users'
Rails 3.0.3 and Ruby 1.9.2 I have the following class class item < ActiveRecord::Base
I have the following named scope in my model class User scope :single_action, where(parent_id
I'm using Rails 3. I have 3 models: class Deal < ActiveRecord::Base has_many :wishes,
I have the following named scope on class RentableItem < ActiveRecord::Base named_scope :available_at, lambda{
I have a the following classes class Service < ActiveRecord::Base has_many :incidents end class
In my Rails 3.2.2 project, I have the following: class Photo < ActiveRecord::Base belongs_to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.