This project is archived and is in readonly mode.

#2341 ✓stale
Akshay Rawat

Nested finder include option with has_one

Reported by Akshay Rawat | March 25th, 2009 @ 05:46 PM | in 3.x

Looks like it is a problem only when there is a has_one relationship.

class Book < ActiveRecord::Base has_one :distributor end

class Distributor < ActiveRecord::Base belongs_to :book has_many :agents end

class Agent < ActiveRecord::Base belongs_to :distributor has_many :shops end

class Shop < ActiveRecord::Base belongs_to :agent end

Schema - http://pastie.org/426261

def test_should_load_avatars shop_1= Shop.create! shop_2= Shop.create! book= Book.create!(:distributor => Distributor.create!(:agents=> [Agent.create!(:shops => [shop_1, shop_2])]))

loaded_version = Book.find(book.id, :include => [:distributor => {:agents => :shops}], :order => 'shops.id')

assert(loaded_version.distributor.agents.first.shops.size == 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 end

This fails on Rails 2.2.2

Thanks, Akshay

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages