|
92 | 92 | t.integer :planet_id |
93 | 93 | end |
94 | 94 |
|
| 95 | + create_table :craters, id: false, force: true do |t| |
| 96 | + t.string :code |
| 97 | + t.string :description |
| 98 | + t.integer :moon_id |
| 99 | + end |
| 100 | + |
95 | 101 | create_table :preferences, force: true do |t| |
96 | 102 | t.integer :person_id |
97 | 103 | t.boolean :advanced_mode, default: false |
@@ -281,6 +287,14 @@ class PlanetType < ActiveRecord::Base |
281 | 287 |
|
282 | 288 | class Moon < ActiveRecord::Base |
283 | 289 | belongs_to :planet |
| 290 | + |
| 291 | + has_many :craters |
| 292 | +end |
| 293 | + |
| 294 | +class Crater < ActiveRecord::Base |
| 295 | + self.primary_key = :code |
| 296 | + |
| 297 | + belongs_to :moon |
284 | 298 | end |
285 | 299 |
|
286 | 300 | class Preferences < ActiveRecord::Base |
@@ -360,7 +374,7 @@ def remove(id) |
360 | 374 | end |
361 | 375 | end |
362 | 376 |
|
363 | | -class CustomerOrder < ActiveRecord::Base |
| 377 | +class Customer < ActiveRecord::Base |
364 | 378 | has_many :purchase_orders |
365 | 379 | end |
366 | 380 |
|
@@ -524,6 +538,9 @@ class PlanetTypesController < JSONAPI::ResourceController |
524 | 538 | class MoonsController < JSONAPI::ResourceController |
525 | 539 | end |
526 | 540 |
|
| 541 | + class CratersController < JSONAPI::ResourceController |
| 542 | + end |
| 543 | + |
527 | 544 | class LikesController < JSONAPI::ResourceController |
528 | 545 | end |
529 | 546 | end |
@@ -861,6 +878,18 @@ class MoonResource < JSONAPI::Resource |
861 | 878 | attribute :description |
862 | 879 |
|
863 | 880 | has_one :planet |
| 881 | + has_many :craters |
| 882 | +end |
| 883 | + |
| 884 | +class CraterResource < JSONAPI::Resource |
| 885 | + attribute :code |
| 886 | + attribute :description |
| 887 | + |
| 888 | + has_one :moon |
| 889 | + |
| 890 | + def self.verify_key(key, context = nil) |
| 891 | + key && String(key) |
| 892 | + end |
864 | 893 | end |
865 | 894 |
|
866 | 895 | class PreferencesResource < JSONAPI::Resource |
@@ -952,6 +981,7 @@ def subject |
952 | 981 | PlanetResource = PlanetResource.dup |
953 | 982 | PlanetTypeResource = PlanetTypeResource.dup |
954 | 983 | MoonResource = MoonResource.dup |
| 984 | + CraterResource = CraterResource.dup |
955 | 985 | PreferencesResource = PreferencesResource.dup |
956 | 986 | EmployeeResource = EmployeeResource.dup |
957 | 987 | FriendResource = FriendResource.dup |
@@ -1226,6 +1256,8 @@ class BadlyNamedAttributesResource < JSONAPI::Resource |
1226 | 1256 | description: 'Saturn is the sixth planet from the Sun and the second largest planet in the Solar System, after Jupiter.', |
1227 | 1257 | planet_type_id: planetoid.id) |
1228 | 1258 | titan = Moon.create(name:'Titan', description: 'Best known of the Saturn moons.', planet_id: saturn.id) |
| 1259 | +crater1 = Crater.create(code:'S56D', description: 'Very large crater', moon_id: titan.id) |
| 1260 | +crater2 = Crater.create(code:'A4D3', description: 'Small crater', moon_id: titan.id) |
1229 | 1261 | makemake = Planet.create(name: 'Makemake', description: 'A small planetoid in the Kuiperbelt.', planet_type_id: planetoid.id) |
1230 | 1262 | uranus = Planet.create(name: 'Uranus', description: 'Insert adolescent jokes here.', planet_type_id: gas_giant.id) |
1231 | 1263 | jupiter = Planet.create(name: 'Jupiter', description: 'A gas giant.', planet_type_id: gas_giant.id) |
|
0 commit comments