I am attempting to construct a join as follows:
UserLog.find(:all, :joins => " JOIN client_inspector ON user_log.COMPUTER_NAME = client_inspector.Retrieving_Hostname ", :select=> "DISTINCT user_log.COMPUTER_NAME, client_inspector.Retrieving_Hostname ")
But its giving me the following error ->
ActiveRecord::StatementInvalid (Mysql2::Error: Table 'user_log.client_inspector' doesn't exist: SELECT DISTINCT user_log.COMPUTER_NAME, client_inspector.Retrieving_Hostname FROM `user_log` JOIN client_inspector ON user_
log.COMPUTER_NAME = client_inspector.Retrieving_Hostname):
I understand the MYSQL error, but why is Rails doing this?
I do not have any Models created associating these two tables together. What I’d like to do is to be able to join via different columns other than the defaults that Ruby builds in.
Is there a different way to do this?
EDIT: I updated to include my actual table names.
Anyone looking for the answer to this, just use this to grab your data ->
This will not return “Model” objects, but just a generic MySQL::Result object. Use this to get the data ->
This will give you an array of arrays like so ->
Also, make sure you qualify your tables with the database name like so ->
My problem turned out to be the qualifying of the database. Since I didn’t qualify, it was looking for the table in the wrong database (the one I was connected to currently).