1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models/reader.rb
Rafael Mendonça França c26a690b99 Merge pull request #14573 from habermann24/has_many_through_fix
Properly handle scoping with has_many :through. Fixes #14537.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/has_many_through_associations_test.rb
2014-04-22 17:20:52 -05:00

23 lines
745 B
Ruby

class Reader < ActiveRecord::Base
belongs_to :post
belongs_to :person, :inverse_of => :readers
belongs_to :single_person, :class_name => 'Person', :foreign_key => :person_id, :inverse_of => :reader
belongs_to :first_post, -> { where(id: [2, 3]) }
end
class SecureReader < ActiveRecord::Base
self.table_name = "readers"
belongs_to :secure_post, :class_name => "Post", :foreign_key => "post_id"
belongs_to :secure_person, :inverse_of => :secure_readers, :class_name => "Person", :foreign_key => "person_id"
end
class LazyReader < ActiveRecord::Base
self.table_name = "readers"
default_scope -> { where(skimmer: true) }
scope :skimmers_or_not, -> { unscope(:where => :skimmer) }
belongs_to :post
belongs_to :person
end