activescaffold/active_scaffold — pull request #259 by robg (2013-03-29 22:47:40+00:00)
Title: Don't trigger an association load when checking for unsaved associations

This fixes an issue where unedited associations were being loaded into memory from the db when performing an update on a record.

As a small example, consider the following:

```ruby
class User < ActiveRecord::Base
has_many :comments
has_many :photos
end

class Comment < ActiveRecord::Base
belongs_to :user
end

class Photo < ActiveRecord::Base
belongs_to :user
end

class UsersController < ActionController::Base
active_scaffold do |config|
config.columns.exclude :photos
end
end

class CommentsController < ActionController::Base
active_scaffold do |config|
# config stuff
end
end
```

When editing a user with via the active scaffold pages and submitting an update, `associated_valid?` will be called on the user record. This will iterate through the User's associations looking for unsaved records to check their validity.

The code as it exists today would invoke both the `comments` and `photos` methods on the record. The comments association will have been marked as loaded since the form submission would populate the target. However, the photos association would have been touched yet as part of the form submission, so invoking the `photos` method and subsequently the `select` iterator would trigger the database call to load all of the user's photos.

This pull request alters the logic to only consider associated objects that have already been instantiated by using the actual Association proxy object to check the `target` and avoiding the possibility of populating the association from the database.