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 6967899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:22:55+00:00 2026-05-27T16:22:55+00:00

I have defined the following two scopes and both working fine: scope :regular_friends, lambda

  • 0

I have defined the following two scopes and both working fine:

scope :regular_friends, lambda { |user| joins{friendships}.where{friendships.user_id.not_in(user)}}
scope :inverse_friends, lambda { |user| joins{inverse_friendships}.where{inverse_friendships.friend_id.not_in(user)}}

I using squeel (https://github.com/ernie/squeel) here and building a self referential association, which is inspired by (http://railscasts.com/episodes/163-self-referential-association).

Based on that, I want to define a third scope which unions the results of the other two:

scope :friends, lambda { |user| User.regular_friends(user).union(User.inverse_friends(user)) }

Unfortunately, it doesn’t work. I am getting a:

NoMethodError (undefined method `default_scoped?' for #<Arel::Nodes::Union:0x8249534>):

I am on Rails 3.1.3. I thought the default_scope? method has been removed in Rails 3.*, but it’s complaining about that…

Can anyone help?

  • 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-05-27T16:22:56+00:00Added an answer on May 27, 2026 at 4:22 pm

    There is no such method as union in Rails (I don’t know about Arel). Just construct the scope as you would normally.

    EDIT:
    You can always use raw sql in the scope definition. I don’t know the details of your application (especially how the tables are interconnected), so I can’t construct the query in its full beauty. Nevertheless, the query will look similar to this:

    scope :friends, find_by_sql(%(
      SELECT users.* FROM users INNER JOIN friendships f on f.user_id = users.#{id} WHERE ...
      UNION
      SELECT users.* FROM users INNER JOIN inverse_friendships i on i.friend_id = users.#{id} WHERE ...
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two classes defined the following way: public class A { public
I have the following two models: School and User, and a HABTM relationship between
Consider the following Spring Service class. The spring scope defined is Singleton. The two
I have the following two procedures defined in my AppDelegate. saveSettings and loadSettings. I
I have the following two routes defined in my MVC app.;- At the moment
I have the following two tables defined... CREATE TABLE [LogLevel] ( [Id] int primary
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
can anyone explain the following to me. I have two JavaScript functions defined in
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] The
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();

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.