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

  • SEARCH
  • Home
  • 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 222035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:05:22+00:00 2026-05-11T19:05:22+00:00

Disclaimer: My original exposure to Ruby on Rails was literally years ago, and a

  • 0

Disclaimer: My original exposure to Ruby on Rails was literally years ago, and a great many things are new to me now that I’m picking it back up. One of these things is named scopes. They seem great, but I’m not getting the result I expect. Here’s a for-instance:

class User
  has_many logs
  named_scope :logged_in, :joins => ['logs'], :conditions => ['logs.logout_at IS NULL']
end

Class Log
  belongs_to user
end

It is my understanding that doing a

User.logged_in

should be exactly the same as doing a

User.find(:all, :joins => ['logs], :conditions => ['logs.logout_at IS NULL'])

But instead, I’m getting back different objects. To demonstrate:

real = User.find_by_name('admin')
  #<User id:12345, name: 'admin' ... >
fake = User.logged_in.find_by_name('admin')
  #<User id: 54321, name: 'admin' ... >

So my question is: Where on earth is this new object coming from, and how do I get named_scope to give me the original one?

  • 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-11T19:05:23+00:00Added an answer on May 11, 2026 at 7:05 pm
    named_scope :logged_in, 
                :conditions => ["logs.logout_at IS NULL"], 
                :include => :logs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Disclaimer: New to Rails here) Say I have a Rails ActiveRecord Model that responds
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Disclaimer : I'm quite a novice to RoR, but not with Ruby (if that
Disclaimer, new to programming, working my way through C++ Prime Plus 6th ed. I'm
Disclaimer : I kept this because some things may be useful to others, however,
I have an app that shows a disclaimer at the beginning of the program.
Disclaimer: I'm new to jQuery and js. I'm trying to hide parts of partials
Disclaimer: Never used php in my life. New to Unix and Jenkins I have
Disclaimer: I'm new to the REST school of thought, and I'm trying to wrap
DISCLAIMER: relatively new to Flex/AS3, I might be missing something obvious. After doing some

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.