|
429 | 429 | t.integer :version |
430 | 430 | t.timestamps null: false |
431 | 431 | end |
| 432 | + |
| 433 | + create_table :contact_media do |t| |
| 434 | + t.string :name |
| 435 | + t.references :party, polymorphic: true, index: true |
| 436 | + end |
| 437 | + |
| 438 | + create_table :individuals do |t| |
| 439 | + t.string :name |
| 440 | + end |
| 441 | + |
| 442 | + create_table :organizations do |t| |
| 443 | + t.string :name |
| 444 | + end |
432 | 445 | end |
433 | 446 |
|
434 | 447 | ### MODELS |
@@ -643,6 +656,22 @@ class Fact < ActiveRecord::Base |
643 | 656 | class Like < ActiveRecord::Base |
644 | 657 | end |
645 | 658 |
|
| 659 | + class TestApplicationRecord < ActiveRecord::Base |
| 660 | + self.abstract_class = true |
| 661 | +end |
| 662 | + |
| 663 | +class ContactMedium < TestApplicationRecord |
| 664 | + belongs_to :party, polymorphic: true, inverse_of: :contact_media |
| 665 | +end |
| 666 | + |
| 667 | +class Individual < TestApplicationRecord |
| 668 | + has_many :contact_media, as: :party |
| 669 | +end |
| 670 | + |
| 671 | +class Organization < TestApplicationRecord |
| 672 | + has_many :contact_media, as: :party |
| 673 | +end |
| 674 | + |
646 | 675 | class Breed |
647 | 676 | include ActiveModel::Model |
648 | 677 |
|
@@ -1246,6 +1275,18 @@ class IndicatorsController < JSONAPI::ResourceController |
1246 | 1275 | class RobotsController < JSONAPI::ResourceController |
1247 | 1276 | end |
1248 | 1277 |
|
| 1278 | +class IndividualsController < BaseController |
| 1279 | +end |
| 1280 | + |
| 1281 | +class OrganizationsController < BaseController |
| 1282 | +end |
| 1283 | + |
| 1284 | +class ContactMediaController < BaseController |
| 1285 | +end |
| 1286 | + |
| 1287 | +class PartiesController < BaseController |
| 1288 | +end |
| 1289 | + |
1249 | 1290 | ### RESOURCES |
1250 | 1291 | class BaseResource < JSONAPI::Resource |
1251 | 1292 | abstract |
@@ -2688,6 +2729,24 @@ class RobotResource < ::JSONAPI::Resource |
2688 | 2729 | end |
2689 | 2730 | end |
2690 | 2731 |
|
| 2732 | +class ContactMediumResource < JSONAPI::Resource |
| 2733 | + attribute :name |
| 2734 | + has_one :party, polymorphic: true |
| 2735 | +end |
| 2736 | + |
| 2737 | +class IndividualResource < JSONAPI::Resource |
| 2738 | + attribute :name |
| 2739 | + has_many :contact_media |
| 2740 | +end |
| 2741 | + |
| 2742 | +class OrganizationResource < JSONAPI::Resource |
| 2743 | + attribute :name |
| 2744 | + has_many :contact_media |
| 2745 | +end |
| 2746 | + |
| 2747 | +class PartyResource < JSONAPI::Resource |
| 2748 | +end |
| 2749 | + |
2691 | 2750 | ### PORO Data - don't do this in a production app |
2692 | 2751 | $breed_data = BreedData.new |
2693 | 2752 | $breed_data.add(Breed.new(0, 'persian')) |
|
0 commit comments