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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:44:12+00:00 2026-06-14T22:44:12+00:00

I have an empty table called users. I create a new user via: User.create

  • 0

I have an empty table called users. I create a new user via:

User.create :fb_id => fb_id

It successfully creates an entry.

Then I query it via:

User.first(:include => :cookies, :conditions => {:cookies => {:opened => false} , :fb_id => fb_id})

returns nil!!

I check the table and the user is there.
So I create a new, duplicate user via:

User.create :fb_id => fb_id

Now there’s exact two row with same fb_id. If I query now just like before:

User.first(:include => :cookies, :conditions => {:cookies => {:opened => false} , :fb_id => fb_id})

it returns the new user now with id 2!

What’s going on? I’ve been trying to debug it for 3-4 hours but can’t figure it out.
Thanks

My Models:

class User < ActiveRecord::Base
    has_many :cookies
    has_many :fortunes, :through => :cookies
end

class Cookie < ActiveRecord::Base
    belongs_to :user
    belongs_to :fortune
end

class Fortune < ActiveRecord::Base
    has_many :cookies
    has_many :users, :through => :cookies
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-14T22:44:16+00:00Added an answer on June 14, 2026 at 10:44 pm

    I believe that Rails will use a left outer join when using include. However, when joining, the associated row, all values will be null. Therefore, you should use something like:

    User.first(:include => :cookies, 
               :conditions => ["cookies.opened <> ? AND fb_id = ?", true, fb_id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity called User which can have a list of other Users
I have a table called USERS that has a foreign key to the table
i have a table called horse, i would like to create a form to
I have dragged a empty asp.net table onto my webform. I generate all the
I have a table with a header and an empty body: <table style=width:50%; class=adminlist>
I have the models User and Group, and the join table Membership which uses
I have a mysql table called pollOfTheWeek. It has a column pollDate of type
I am developing a system that will eventually have millions of users. Each user
I have a table with a series of codes, which has a field called
I have a data table. Each row of the table has a commandButton called

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.