rails/rails — Issue #3922: Three relationships to common class
Author: josemota
Created: 2011-12-09 20:21:38+00:00
State: open

Hi everyone, I have been struggling with a situation on multiple associations with the same class_name. I have talked to a Ruby friend nearby and he agreed that this could possibly be a bug.

Please consider the following:

### Models

```ruby
class Record < ActiveRecord::Base
has_many :events

has_one :first_term_test, :class_name => "Event"
has_one :first_term_audition, :class_name => "Event"
end

class Event < ActiveRecord::Base
belongs_to :record
end
```

I have ran a console session and here's what I have got:

```ruby
r = Record.first # #
r.events.map(&:id) # [ 2, 7, 8 ]

r.first_term_test_id # 7
r.first_term_test.id
# SELECT "events".* FROM "events" WHERE "events"."record_id" = 1 LIMIT 1
# --> 2

r.first_term_audition_id # 8
r.first_term_audition.id
# SELECT "events".* FROM "events" WHERE "events"."record_id" = 1 LIMIT 1
# --> 2
```

I am using:

* Ruby 1.9.3-p0
* Rails 3.1.3
* RVM 1.9.1
* Mac OS X 10.7

Thanks guys. Let me know if you need any more info.