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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:29:06+00:00 2026-06-08T21:29:06+00:00

I have the following model: class Party < ActiveRecord::Base has_many :party_characters has_many :characters, :through

  • 0

I have the following model:

class Party < ActiveRecord::Base
  has_many :party_characters
  has_many :characters, :through => :party_characters
  ...

And on my controller I have the following code:

def new
  @party = Party.new
  p @party.characters.any?
  p @party.characters
  p @party.characters.any?
  ...

That writes the following to the console:

true
[]
false

Why does the any? method returns true before the print and false after?

  • 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-08T21:29:08+00:00Added an answer on June 8, 2026 at 9:29 pm

    Tried the same thing on the console and got the following results

    1.9.3p0 :003 > p = Party.new
     => #<Party id: nil, name: nil, created_at: nil, updated_at: nil> 
    1.9.3p0 :004 > p.characters.any?
       (17.9ms)  SELECT COUNT(*) FROM "characters" INNER JOIN "party_characters" ON "characters"."id" = "party_characters"."character_id" WHERE "party_characters"."party_id" IS NULL
     => true 
    1.9.3p0 :005 > p.characters
     => [] 
    1.9.3p0 :006 > p.characters.any?
     => false 
    

    So I decided to check what I had on the party_characters table and found entries with a valid character_id but with a nil party id. I removed those and everything works as supposed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: # app/models/part.rb class Part < ActiveRecord::Base has_many :lots #
Ok say I have the following model: class Country < ActiveRecord::Base validates_presence_of :name validates_presence_of
I have the following model associations: class Slider < ActiveRecord::Base has_one :featured_happening, :as =>
I have a model with the following associations: class Car < ActiveRecord::Base belongs_to :transportation_vehicle
I have the following code in a view: def controller_details(request, object_id): controller = Controller.objects.get(pk=object_id)
I have two related models such as this: class PartCategory < ActiveRecord::Base has_many :part_types
I have the following model: class User: name = models.CharField( max_length = 200 )
hi i have to following model class Match(models.Model): Team_one = models.ForeignKey('Team', related_name='Team_one') Team_two =
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I am using appengine, webapp2 framework. I have the following model: class Match(db.Model): date_time

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.