我使用Rails 5并尝试做下一步
class Song
has_and_belongs_to_many :artists
end
class UnknownSong
end
class Library
belongs_to :media, polymorphic: true
belongs_to :song, foreign_key: :media_id, foreign_type: :media_type
belongs_to :unknown_song, foreign_key: :media_id, foreign_type: :media_type
end
当我运行此查询时
Library.includes(song: [:artists], :unknown_song)
rails生成下一个sql
SELECT "songs".* FROM "songs" WHERE "songs"."id" IN (391497, 921, 1469, 172)
SELECT "unknown_songs".* FROM "unknown_songs" WHERE "unknown_songs"."id" IN (391497, 921, 1469, 172)
并尝试使用相同的ID加载不同的多态模型
data in database
如何解决这个问题?