Skip to content
Snippets Groups Projects
Commit 57b6f101 authored by Wellington Gabriel Vicente de Souza's avatar Wellington Gabriel Vicente de Souza
Browse files

add working model relationships and destroy methods

parent 168b5706
No related branches found
No related tags found
No related merge requests found
......@@ -4,13 +4,14 @@ ActiveRecord::Base.establish_connection :adapter => "sqlite3",
:database => "steamdb.sqlite3"
class Game < ActiveRecord::Base;
has_one :price
has_one :price, dependent: :destroy
belongs_to :developer
has_and_belongs_to_many :categories
has_many :category_games
has_many :categories, through: :category_games, dependent: :destroy
end
class Developer < ActiveRecord::Base;
has_many :games
has_many :games, dependent: :destroy
end
class Price < ActiveRecord::Base;
......@@ -18,5 +19,11 @@ class Price < ActiveRecord::Base;
end
class Category < ActiveRecord::Base;
has_and_belongs_to_many :games
has_many :category_games
has_many :games, through: :category_games, dependent: :destroy
end
class CategoryGame < ActiveRecord::Base;
belongs_to :category
belongs_to :game
end
\ No newline at end of file
......@@ -28,7 +28,7 @@ ActiveRecord::Base.connection.create_table :categories do |t|
t.text :description
end
ActiveRecord::Base.connection.create_table :categories_games, id: false do |t|
ActiveRecord::Base.connection.create_table :category_games, id: false do |t|
t.references :category
t.references :game
end
\ No newline at end of file
end
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment