Creating a new GameTheme model for verification purposes is not a good idea. We can affirm ourselves in the process of migration.
Thematic Model:
class Theme < ActiveRecord::Base has_and_belongs_to_many :games, :association_foreign_key => 'theme_id', :class_name => 'Theme', :join_table => 'games_themes' end
Game model:
class Theme < ActiveRecord::Base has_and_belongs_to_many :games, :association_foreign_key => 'game_id', :class_name => 'Game', :join_table => 'games_themes' end
games_themes mig: You can add uniqueness to the connection table, see here for more details.
class GamesThemesTable < ActiveRecord::Migration def self.up create_table :games_themes, :id => false do |t| t.references :game t.references :theme end add_index :games_themes, [:theme_id, :game_id], :unique => true end def self.down drop_table :games_themes end end
Pravin mishra
source share