|
291 | 291 | t.timestamps null: false |
292 | 292 | end |
293 | 293 |
|
| 294 | + create_table :questions, force: true do |t| |
| 295 | + t.string :text |
| 296 | + end |
| 297 | + |
| 298 | + create_table :answers, force: true do |t| |
| 299 | + t.references :question |
| 300 | + t.integer :respondent_id |
| 301 | + t.string :respondent_type |
| 302 | + t.string :text |
| 303 | + end |
| 304 | + |
| 305 | + create_table :patients, force: true do |t| |
| 306 | + t.string :name |
| 307 | + end |
| 308 | + |
| 309 | + create_table :doctors, force: true do |t| |
| 310 | + t.string :name |
| 311 | + end |
| 312 | + |
294 | 313 | # special cases |
295 | 314 | end |
296 | 315 |
|
@@ -606,6 +625,25 @@ class RelatedThing < ActiveRecord::Base |
606 | 625 | belongs_to :to, class_name: Thing, foreign_key: :to_id |
607 | 626 | end |
608 | 627 |
|
| 628 | +class Question < ActiveRecord::Base |
| 629 | + has_one :answer |
| 630 | + |
| 631 | + def respondent |
| 632 | + answer.try(:respondent) |
| 633 | + end |
| 634 | +end |
| 635 | + |
| 636 | +class Answer < ActiveRecord::Base |
| 637 | + belongs_to :question |
| 638 | + belongs_to :respondent, polymorphic: true |
| 639 | +end |
| 640 | + |
| 641 | +class Patient < ActiveRecord::Base |
| 642 | +end |
| 643 | + |
| 644 | +class Doctor < ActiveRecord::Base |
| 645 | +end |
| 646 | + |
609 | 647 | module Api |
610 | 648 | module V7 |
611 | 649 | class Client < Customer |
@@ -882,6 +920,21 @@ class BoxesController < JSONAPI::ResourceController |
882 | 920 | end |
883 | 921 | end |
884 | 922 |
|
| 923 | +class QuestionsController < JSONAPI::ResourceController |
| 924 | +end |
| 925 | + |
| 926 | +class AnswersController < JSONAPI::ResourceController |
| 927 | +end |
| 928 | + |
| 929 | +class PatientsController < JSONAPI::ResourceController |
| 930 | +end |
| 931 | + |
| 932 | +class DoctorsController < JSONAPI::ResourceController |
| 933 | +end |
| 934 | + |
| 935 | +class RespondentController < JSONAPI::ResourceController |
| 936 | +end |
| 937 | + |
885 | 938 | ### RESOURCES |
886 | 939 | class BaseResource < JSONAPI::Resource |
887 | 940 | abstract |
@@ -1795,6 +1848,30 @@ class UserResource < JSONAPI::Resource |
1795 | 1848 | end |
1796 | 1849 | end |
1797 | 1850 |
|
| 1851 | +class QuestionResource < JSONAPI::Resource |
| 1852 | + has_one :answer |
| 1853 | + has_one :respondent, polymorphic: true, class_name: "Respondent", foreign_key_on: :related |
| 1854 | + |
| 1855 | + attributes :text |
| 1856 | +end |
| 1857 | + |
| 1858 | +class AnswerResource < JSONAPI::Resource |
| 1859 | + has_one :question |
| 1860 | + has_one :respondent, polymorphic: true |
| 1861 | +end |
| 1862 | + |
| 1863 | +class PatientResource < JSONAPI::Resource |
| 1864 | + attributes :name |
| 1865 | +end |
| 1866 | + |
| 1867 | +class DoctorResource < JSONAPI::Resource |
| 1868 | + attributes :name |
| 1869 | +end |
| 1870 | + |
| 1871 | +class RespondentResource < JSONAPI::Resource |
| 1872 | + abstract |
| 1873 | +end |
| 1874 | + |
1798 | 1875 | ### PORO Data - don't do this in a production app |
1799 | 1876 | $breed_data = BreedData.new |
1800 | 1877 | $breed_data.add(Breed.new(0, 'persian')) |
|
0 commit comments