This project is archived and is in readonly mode.

#3472 ✓resolved
Dmitry Ratnikov

AssociationCollection#include? ignoring build associated objects

Reported by Dmitry Ratnikov | November 9th, 2009 @ 05:59 AM | in 2.3.10


class Post < ActiveRecord::Base
  has_many :comments

class Comment < ActiveRecord::Base
  belongs_to :post

The following test fails:

def test_build
  post =
  comment =
  assert post.comments.include?(comment)

The logs show:

  Comment Load (0.2ms)   SELECT "comments".id FROM "comments" WHERE ("comments"."id" = NULL) AND ("comments".post_id = NULL) LIMIT 1

It seems that the collection ignores that it has been setup (loaded? #=> false) and reloads it from the database. Regarding that the database is a new record and hence definitely cannot be in the database, that is probably not expected behavior.

Any suggestions?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by