|
429 | 429 | t.integer :version |
430 | 430 | t.timestamps null: false |
431 | 431 | end |
| 432 | + |
| 433 | + # Tables for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related |
| 434 | + create_table :articles, force: true do |t| |
| 435 | + t.string :title |
| 436 | + t.timestamps null: false |
| 437 | + end |
| 438 | + |
| 439 | + create_table :article_comments, force: true do |t| |
| 440 | + t.text :content |
| 441 | + t.references :commentable, polymorphic: true, index: true |
| 442 | + t.timestamps null: false |
| 443 | + end |
432 | 444 | end |
433 | 445 |
|
434 | 446 | ### MODELS |
@@ -868,6 +880,15 @@ class ListItem < ActiveRecord::Base |
868 | 880 | belongs_to :list, inverse_of: :items |
869 | 881 | end |
870 | 882 |
|
| 883 | +# Models for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related |
| 884 | +class Article < ActiveRecord::Base |
| 885 | + has_many :article_comments, as: :commentable |
| 886 | +end |
| 887 | + |
| 888 | +class ArticleComment < ActiveRecord::Base |
| 889 | + belongs_to :commentable, polymorphic: true |
| 890 | +end |
| 891 | + |
871 | 892 | ### CONTROLLERS |
872 | 893 | class SessionsController < ActionController::Base |
873 | 894 | include JSONAPI::ActsAsResourceController |
@@ -1230,6 +1251,13 @@ class IndicatorsController < JSONAPI::ResourceController |
1230 | 1251 | class RobotsController < JSONAPI::ResourceController |
1231 | 1252 | end |
1232 | 1253 |
|
| 1254 | +# Controllers for testing Issue #1473 |
| 1255 | +class ArticlesController < JSONAPI::ResourceController |
| 1256 | +end |
| 1257 | + |
| 1258 | +class ArticleCommentsController < JSONAPI::ResourceController |
| 1259 | +end |
| 1260 | + |
1233 | 1261 | ### RESOURCES |
1234 | 1262 | class BaseResource < JSONAPI::Resource |
1235 | 1263 | abstract |
@@ -2691,6 +2719,17 @@ class RobotResource < ::JSONAPI::Resource |
2691 | 2719 | end |
2692 | 2720 | end |
2693 | 2721 |
|
| 2722 | +# Resources for testing Issue #1473: Polymorphic has_many with foreign_key_on: :related |
| 2723 | +class ArticleResource < JSONAPI::Resource |
| 2724 | + attribute :title |
| 2725 | + has_many :article_comments, foreign_key_on: :related |
| 2726 | +end |
| 2727 | + |
| 2728 | +class ArticleCommentResource < JSONAPI::Resource |
| 2729 | + attribute :content |
| 2730 | + has_one :commentable, polymorphic: true |
| 2731 | +end |
| 2732 | + |
2694 | 2733 | # Models and Resources for testing Issue #1467: ActiveModel-based resources |
2695 | 2734 | # ActiveModel class without ActiveRecord |
2696 | 2735 | class SimpleModel |
|
0 commit comments