rails/rails — Issue #3522: TooManyRecords error raises when I want to update nested attributes
Author: berrouz
Created: 2011-11-05 01:08:11+00:00
State: open

I have the following association:
employee has_many projects
accept_nested_attribites_for :projects, :allow_destroy => true, :limit => 2

If, for example, my model has already 2 projects associated with it and I want to update those projects, I always get an error TooManyRecords. I think it occurs because I have 2 records assigned + 1 new added record. Despite I marked 1 old record for deletion, the verification process of MAX size of associated records

attributes_collection.size > options[:limit]

is being done before unneeded associated records get destroyed(accordingly to "_destroy" parameter, which should be set to true)

Thus, I think we should take into consideration that some records are gonna be deleted and doesn't count them when check this condition.

Thanks beforehand