aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-02-14 23:14:42 +0000
committerJon Leighton <j@jonathanleighton.com>2011-02-18 00:00:13 +0000
commit91fd6510563f84ee473bb217bc63ed598abe3f24 (patch)
tree8d9a4996e5a7b9663e8bd7869d62c9701e5385de /activerecord/test/models
parentf0b98050296b57d95dbc789f8e52fa82499d151a (diff)
downloadrails-91fd6510563f84ee473bb217bc63ed598abe3f24.tar.gz
rails-91fd6510563f84ee473bb217bc63ed598abe3f24.tar.bz2
rails-91fd6510563f84ee473bb217bc63ed598abe3f24.zip
Allow building and then later saving has_many :through records, such that the join record is automatically saved too. This requires the :inverse_of option to be set on the source association in the join model. See the CHANGELOG for details. [#4329 state:resolved]
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/person.rb2
-rw-r--r--activerecord/test/models/post.rb1
-rw-r--r--activerecord/test/models/reader.rb3
3 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index a18b9e44df..cc3a4f5f9d 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -1,5 +1,7 @@
class Person < ActiveRecord::Base
has_many :readers
+ has_one :reader
+
has_many :posts, :through => :readers
has_many :posts_with_no_comments, :through => :readers, :source => :post, :include => :comments, :conditions => 'comments.id is null'
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 1bbcab3a39..a342aaf60b 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -95,6 +95,7 @@ class Post < ActiveRecord::Base
has_many :readers
has_many :readers_with_person, :include => :person, :class_name => "Reader"
has_many :people, :through => :readers
+ has_many :single_people, :through => :readers
has_many :people_with_callbacks, :source=>:person, :through => :readers,
:before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
:after_add => lambda {|owner, reader| log(:added, :after, reader.first_name) },
diff --git a/activerecord/test/models/reader.rb b/activerecord/test/models/reader.rb
index 27527bf566..0207a2bd92 100644
--- a/activerecord/test/models/reader.rb
+++ b/activerecord/test/models/reader.rb
@@ -1,4 +1,5 @@
class Reader < ActiveRecord::Base
belongs_to :post
- belongs_to :person
+ belongs_to :person, :inverse_of => :readers
+ belongs_to :single_person, :class_name => 'Person', :foreign_key => :person_id, :inverse_of => :reader
end