Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.

Commit dfc6c94

Browse files
authored
Merge pull request #14 from GraphQLAcademy/add-species
Add Species model, associations, and fixtures
2 parents bb04f4a + c137619 commit dfc6c94

8 files changed

Lines changed: 621 additions & 1 deletion

File tree

app/models/person.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Person < ApplicationRecord
22
belongs_to :homeworld, class_name: 'Planet'
3+
belongs_to :species
34

45
has_and_belongs_to_many :starships
56
has_and_belongs_to_many :vehicles

app/models/species.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Species < ApplicationRecord
2+
belongs_to :homeworld, class_name: 'Planet'
3+
has_many :people
4+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateSpecies < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :species do |t|
4+
t.string :name
5+
t.string :classification
6+
t.string :designation
7+
t.float :average_height
8+
t.integer :average_lifespan
9+
t.string :eye_colors
10+
t.string :hair_colors
11+
t.string :skin_colors
12+
t.string :language
13+
t.references :homeworld, foreign_key: true
14+
15+
t.timestamps
16+
end
17+
end
18+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddSpeciesToPeople < ActiveRecord::Migration[5.0]
2+
def change
3+
change_table :people do |t|
4+
t.references :species, foreign_key: true
5+
end
6+
end
7+
end

db/schema.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20170209173854) do
13+
ActiveRecord::Schema.define(version: 20170210214836) do
1414

1515
create_table "people", force: :cascade do |t|
1616
t.string "name"
@@ -24,7 +24,9 @@
2424
t.integer "homeworld_id"
2525
t.datetime "created_at", null: false
2626
t.datetime "updated_at", null: false
27+
t.integer "species_id"
2728
t.index ["homeworld_id"], name: "index_people_on_homeworld_id"
29+
t.index ["species_id"], name: "index_people_on_species_id"
2830
end
2931

3032
create_table "people_starships", id: false, force: :cascade do |t|
@@ -55,6 +57,22 @@
5557
t.datetime "updated_at", null: false
5658
end
5759

60+
create_table "species", force: :cascade do |t|
61+
t.string "name"
62+
t.string "classification"
63+
t.string "designation"
64+
t.float "average_height"
65+
t.integer "average_lifespan"
66+
t.string "eye_colors"
67+
t.string "hair_colors"
68+
t.string "skin_colors"
69+
t.string "language"
70+
t.integer "homeworld_id"
71+
t.datetime "created_at", null: false
72+
t.datetime "updated_at", null: false
73+
t.index ["homeworld_id"], name: "index_species_on_homeworld_id"
74+
end
75+
5876
create_table "starships", force: :cascade do |t|
5977
t.string "name"
6078
t.string "model"

0 commit comments

Comments
 (0)