How to use joins or other ways to let me use the where query to compare other conditions in another model?
Model relation
class SonyAlarmLog < ActiveRecord::Base
belongs_to :sony_alarm_test
class SonyAlarmTest < ActiveRecord::Base
has_many :sony_alarm_bugs, :dependent => :destroy
It works, but returns me the columns of the SonyAlarmTest
, I wanna the columns of sony_alarm_logs
SonyAlarmTest.joins{:sony_alarm_logs}
.where{ sony_alarm_logs.name =~ event_name }
It failed, get the ActiveRecord::ConfigurationError: Association named 'sony_alarm_tests' was not found on SonyAlarmLog; perhaps you misspelled it?
Error
SonyAlarmLog.joins(:sony_alarm_tests)
.where{ name =~ event_name }
UPDATE (Fix: it should use the singular name)
But still got ActiveModel::MissingAttributeError: missing attribute: firmware_version
error
I thought it may be mis-use of squeel syntax ?
SonyAlarmLog.joins(:sony_alarm_test)
.where{ name =~ event_name }
.where{ utc_time.gt (my{utc_time} + TIME_CORRECTION) }
.where{ sony_alarm_tests.round.eq(my{sony_alarm_test.round}) }
.where{ sony_alarm_tests.ip =~ my{sony_alarm_test.ip} }
.where{ sony_alarm_tests.firmware_version =~ my{sony_alarm_test.firmware_version} }