I have a “answers” table and a “users” table. I need to link them but I have to use custom keys on both tables (i.e. I’m not using ‘id’ in any of them). Both tables have the “facebook_id” field which connects them.
In the Answer model I define a “belongs_to” User, and I can define Answer’s foreign_key, but how can I say “link Answer to User using facebook_id on both tables”?
It appears the only way this is possible is by changing your models
_primary_keytofacebook_idUpon investigation of the ORM class structure you’ll see the tables are joined like so
As you mentioned you can use
But that would result in
But if you change the primary key on answers from id to facebook_id like so
Then of course the final query would result in