aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorUlisses Almeida + Kassio Borges <anizark+kassioborgesm@gmail.com>2014-12-08 17:43:16 -0200
committerUlisses Almeida + Kassio Borges <anizark+kassioborgesm@gmail.com>2014-12-08 18:13:15 -0200
commit075c81feec87b1e5bfec27ed585c4ab613c2d174 (patch)
tree2fad903219acd89c1437d83c9b7737da3b14292e /activerecord/test/models
parent7daeb98c769a3968a2ccf48ff593909bf1a9d7b0 (diff)
downloadrails-075c81feec87b1e5bfec27ed585c4ab613c2d174.tar.gz
rails-075c81feec87b1e5bfec27ed585c4ab613c2d174.tar.bz2
rails-075c81feec87b1e5bfec27ed585c4ab613c2d174.zip
Add foreign_type option for polymorphic has_one and has_many.
To be possible to use a custom column name to save/read the polymorphic associated type in a has_many or has_one polymorphic association, now users can use the option :foreign_type to inform in what column the associated object type will be saved.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/image.rb3
-rw-r--r--activerecord/test/models/post.rb3
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/models/image.rb b/activerecord/test/models/image.rb
new file mode 100644
index 0000000000..7ae8e4a7f6
--- /dev/null
+++ b/activerecord/test/models/image.rb
@@ -0,0 +1,3 @@
+class Image < ActiveRecord::Base
+ belongs_to :imageable, foreign_key: :imageable_identifier, foreign_type: :imageable_class
+end
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 57e1818e49..56073cc588 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -128,6 +128,9 @@ class Post < ActiveRecord::Base
has_many :taggings_using_author_id, :primary_key => :author_id, :as => :taggable, :class_name => 'Tagging'
has_many :tags_using_author_id, :through => :taggings_using_author_id, :source => :tag
+ has_many :images, :as => :imageable, :foreign_key => :imageable_identifier, :foreign_type => :imageable_class
+ has_one :main_image, :as => :imageable, :foreign_key => :imageable_identifier, :foreign_type => :imageable_class, :class_name => 'Image'
+
has_many :standard_categorizations, :class_name => 'Categorization', :foreign_key => :post_id
has_many :author_using_custom_pk, :through => :standard_categorizations
has_many :authors_using_custom_pk, :through => :standard_categorizations