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?
Tried the same thing on the console and got the following results
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.