When using deeply nested has many associations in include with conditions in include, will the conditional only be called for the first record. This PR is a fix to that bug.
Example:
class User < ActiveRecord::Base
has_many :orders
end
class Order < ActiveRecord::Base
belongs_to :user
has_many :products
end
class Product < ActiveRecord::Base
belongs_to :order
end
# Create a user with two orders, each with two products
@user = User.create :name => 'Jack'
@product1 = Product.create :name => 'Paper'
@product2 = Product.create :name => 'Ink'
@order1 = Order.create
@order2 = Order.create
@order1.products << [@product1, @product2]
@order2.products << [@product1, @product2]
@user.orders << [@order1, @order2]
# We don't want to clone the "Ink" product
deep_clone = @user.deep_clone(:include => [orders: [products: [{ :unless => lambda {|product| product.name == 'Ink' }}]]])
# However the conditional only works for the first order, because after that is the conditional deleted from the hash
deep_clone.orders[0].products.size #=> 1
deep_clone.orders[1].products.size #=> 2
When using deeply nested has many associations in include with conditions in include, will the conditional only be called for the first record. This PR is a fix to that bug.
Example: