belongs_to with :class_name option

77 views
Skip to first unread message

Ryan Kinderman

unread,
Nov 16, 2007, 9:12:25 PM11/16/07
to Composite Keys for ActiveRecord
The code does not properly determine the primary_key_name value from
the association reflection when a 'belongs_to' association is
specified with the :class_name option. Example from the patch I've
submitted:

class Reading < ActiveRecord::Base
belongs_to :article
belongs_to :reader, :class_name => "User"
end

Failing test:

def test_belongs_to_with_class_name
@reading = Reading.find(:first)
assert_not_nil @reading.reader
end

The value of AssociationReflection#primary_key_name in this case will
be "user_id" instead of "reader_id", as it should be.

Patch file:
http://compositekeys.googlegroups.com/web/belongs_to_with_class_name.patch

Ryan Kinderman

unread,
Nov 21, 2007, 9:37:56 PM11/21/07
to Composite Keys for ActiveRecord
Reply all
Reply to author
Forward
0 new messages