I am migrating from Rails 4 to Rails 5 and got into this problem. I have the hasMany
through
relationship to connect the Track
and the RightHolder
classes:
class RightHolder < ActiveRecord::Base
has_many :right_holder_tracks, class_name: 'TrackRightHolder', dependent: :delete_all
has_many :tracks, -> { uniq }, through: :right_holder_tracks
end
class TrackRightHolder < ActiveRecord::Base
belongs_to :track
belongs_to :right_holder
end
class Track < ActiveRecord::Base
has_many :track_right_holders, dependent: :destroy
has_many :right_holders, -> { uniq }, through: :track_right_holders
end
In Rails 4 this was working perfectly, but in Rails 5, when I try to get:
Track.first.right_holders
RightHolder.first.tracks
The Rails application does these queries:
select * from right_holders
select * from tracks
What am I doing wrong? Is this a bug?