I think ActiveRecord will expect this join condition to work: on members.id = invitation.member_id
Would that work on your data? I think that in both of those association declarations, the :foreign_key argument names the field in the child table that should be linked to the pk of the parent (is that right?). So if you want member_id to be the pk of the members table, you need to add a primary_key declaration on your members class (in which case you should probably ditch the members.id field, as it's liable to cause confusion). I'd either do that, or rename members.member_id to something like members.legacy_member_id. That would keep you clear of the rails conventions. -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Greg Lazarev Sent: Wednesday, October 29, 2008 2:19 PM To: [email protected] Subject: [Rails] Foreign key question Here's my situation: Let's say, I have a "members" table that tools like this: id | member_id | name | and I have a "invitation" table that looks like this: id | member_id | date | In my case, invitation.member_id needs to be the key to reference members.member_id What do I need to do in my models so I can do things like: member.invitation.date I've tried doing: class Member has_one :invitation, :foreign_key => "member_id" end class Invitation belongs_to :member, :foreign_key => "member_id" end Any ideas? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

