I am having difficulties finding the right combination to setup my foreign keys. No matter what I do my console is still reading zip_ids when it should be zip_codes only.
I am receiving this in the console:
Zip.code(30052).users.count
Zip Load (12.5ms) SELECT `zips`.* FROM `zips` WHERE `zips`.`code` = 30052 LIMIT 1
(0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`zip_code` = 12859
=> 0
The issue is the second line where it is somehow pulling zip code 12859, which I never specified. This is because it is using zip_id instead of zip_code from the user table.
zip.rb:
has_many :users, :foreign_key => "zip_code"
user.rb :
belongs_to :zip