Rails 4, Active Record, Nitrous.io, Heroku, PostgreSQL.
The most_important_table in the Rails app I am coding contains records that each have a unique identifier (examples: "912828J27", "US38141EC238"), call it uniq_alphanum_identifier. My application (LEFT OUTER) joins several other tables' data ON most_important_table.uniq_alphanum_identifier.
Since I am not using my records' primary key for joining, I feel I am not leveraging my model associations and am finding myself writing SQL queries by hand using methods like .connection.select_all or .find_by_sql. But this doesn't seem "right." Why? SQL queries written by hand are tough to maintain and database dependent. "Last resort" is what the documentation calls these methods. (http://apidock.com/rails/ActiveRecord/Base/find_by_sql/class)
Question: how can I set up model associations using uniq_alphanum_identifier (is this even possible?) so that I can leverage my model associations and (hopefully) utilize Rails' query methods to eliminate writing queries by hand?