Prevent undefined variable problems when using an association as primary key