diff options
author | Jason Rush <diminish7@gmail.com> | 2012-04-05 13:21:48 -0600 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-11-29 05:50:34 +0000 |
commit | 89b5b31cc4f8407f648a2447665ef23f9024e8a5 (patch) | |
tree | 721b47a8f33bf70851736164bf4a80cdd7c59e94 /activerecord/test/models | |
parent | eba430aecbce963f5b2d91ef6a9c36aec8c824bb (diff) | |
download | rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.gz rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.bz2 rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.zip |
Added STI support to init and building associations
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/author.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/company.rb | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 77f4a2ec87..6935cfb0ea 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -1,5 +1,6 @@ class Author < ActiveRecord::Base has_many :posts + has_one :post has_many :very_special_comments, :through => :posts has_many :posts_with_comments, -> { includes(:comments) }, :class_name => "Post" has_many :popular_grouped_posts, -> { includes(:comments).group("type").having("SUM(comments_count) > 1").select("type") }, :class_name => "Post" diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 17b17724e8..3ca8f69646 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -111,6 +111,7 @@ end class DependentFirm < Company has_one :account, :foreign_key => "firm_id", :dependent => :nullify has_many :companies, :foreign_key => 'client_of', :dependent => :nullify + has_one :company, :foreign_key => 'client_of', :dependent => :nullify end class RestrictedFirm < Company |