How can I use a joins to query an associated model in rails 5? What I've tried is DoctorLocation.joins(:location).where(:location => {:confidence => 2})
after looking at the documentation and this question. What am I doing wrong? My query isn't returning any results.
pry(main)> DoctorLocation.joins(:locations).where(:locations => {:confidence => 2})
=> #<DoctorLocation::ActiveRecord_Relation:0x3ff735a09d8c>
class DoctorLocation
belongs_to :location
end
class Location
has_many :doctor_locations, dependent: :destroy
end
Migration
create_table :doctor_locations do |t|
t.integer :doctor_profile_id
t.integer :location_id
t.text :uuid
t.timestamps null: false
end
create_table :locations do |t|
t.string :address
t.integer :ordinal, :default => 1
t.integer :doctor_profile_id
t.text :uuid
t.timestamps
end
add_column :locations, :confidence, :integer