Machinist's #make breaks on has_many associations when defining method `empty?`

Updated . Posted . Visible to the public.

Observed on Rails 2.3 and machinist 1.0.6

Like the title says, when you define the method empty? like in the following example, you may not longer use collection.make.

class Book

  has_many :pages

  def empty?
    pages.empty?
  end

end

Assuming

b1 = Book.find(1)
b2 = Book.find(2)

instead of expected

b1.pages.make #=> #<Page id: 1, book_id: 1>
b2.pages.make #=> #<Page id: 2, book_id: 2>

you'll get

b1.pages.make #=> #<Page id: 1, book_id: 3>
b2.pages.make #=> #<Page id: 2, book_id: 4>

So if you want to keep your empty? method, from now on you have to write

page = Page.make(:book => b1)

to reliably add records to the collection.

Last edit
Deleted user #6
Keywords
Object.association.make
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2011-09-07 08:22)