rails/rails — pull request #6605 by amatsuda (2012-06-03 04:59:51+00:00)
Title: a test case that ensures AR::Relation#merge can merge associations

I was writing a tiny patch enabling `AR::Relation#merge` to accept a collection association instance.
In AR 3 we need to call `scoped` like this, but I thought it could be done implicitly.

```
euruko = Conference.find_by_name('euruko')
# runs separate queries for Relation and association
Attendee.where(name: 'matz').merge(euruko.attendees)

Attendee Load (0.3ms) SELECT "attendees".* FROM "attendees" WHERE "attendees"."conference_id" = 1
Attendee Load (0.2ms) SELECT "attendees".* FROM "attendees" WHERE "attendees"."name" = 'matz'
```

```
# merging into one query
Attendee.where(name: 'matz').merge(euruko.attendees.scoped)

Attendee Load (0.3ms) SELECT "attendees".* FROM "attendees" WHERE "attendees"."name" = 'matz' AND "attendees"."conference_id" = 1
```

So I finished writing my patch, rebased my patch against master, then noticed that this feature was already implemented in the series of `merge` refactoring done by @jonleighton
I'm not sure whether this was intentional or not (because there's no explicit test case for this), but I love this feature to be officially supported. So let me push my test case alone.