ととの 3 つのモデルがPoemあります。ユーザーは、任意の数の詩や歌に投票できます。SongUser
1 つの解決策は、2 つの関連付けモデルを作成PoemVoteし、SongVote
class PoemVote
attr_accessible :poem_id, :user_id
belongs_to :poem
belongs_to :user
end
class SongVote
attr_accessible :song_id, :user_id
belongs_to :song
belongs_to :user
end
私は電話をかけることができsome_poem_vote.poemますsome_song_vote.song
ただし、PoemVoteとSongVoteは本質的に同じです。Vote単一のテーブル継承を使用して、1 つの親クラスから 2 つを拡張するにはどうすればよいですか?
私はこれらの線に沿って何かを考えています:
class Vote
attr_accessible :resource_id, :user_id
end
class PoemVote < Vote
...not sure what goes here...
end
class SongVote < Vote
...not sure what goes here...
end
some_poem_vote.poemPoemVotes と SongVotes が 1 つのデータベース テーブルを共有できるようにするにはどうすればよいですか? または、私の問題に対するより良い解決策はありますか?