1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix undefined method `owners' for NullPreloader:Class

* Fix undefined method `owners' for NullPreloader:Class

Fixing undefined method `owners' for
ActiveRecord::Associations::Preloader::NullPreloader:Class

* Use Ruby 1.9 hash format

Use Ruby 1.9 hash format

#24192

[Rafael Mendonça França + Ladislav Smola]
This commit is contained in:
Ladislav Smola 2016-04-06 05:46:55 +02:00 committed by Rafael França
parent ff982e4188
commit cb4f6875b6
6 changed files with 32 additions and 1 deletions

View file

@ -184,6 +184,7 @@ module ActiveRecord
def self.new(klass, owners, reflection, preload_scope); self; end
def self.run(preloader); end
def self.preloaded_records; []; end
def self.owners; []; end
end
# Returns a class containing the logic needed to load preload the data

View file

@ -11,7 +11,9 @@ require 'models/tagging'
require 'models/author'
require 'models/owner'
require 'models/pet'
require 'models/pet_treasure'
require 'models/toy'
require 'models/treasure'
require 'models/contract'
require 'models/company'
require 'models/developer'
@ -1082,6 +1084,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [], person.posts
end
def test_preloading_empty_through_with_polymorphic_source_association
owner = Owner.create!(name: "Rainbow Unicat")
pet = Pet.create!(owner: owner)
person = Person.create!(first_name: "Gaga")
treasure = Treasure.create!(looter: person)
non_looted_treasure = Treasure.create!()
PetTreasure.create!(pet: pet, treasure: treasure, rainbow_color: "Ultra violet indigo")
PetTreasure.create!(pet: pet, treasure: non_looted_treasure, rainbow_color: "Ultra violet indigo")
assert_equal [person], Owner.where(name: "Rainbow Unicat").includes(pets: :persons).first.persons.to_a
end
def test_explicitly_joining_join_table
assert_equal owners(:blackbeard).toys, owners(:blackbeard).toys.with_pet
end

View file

@ -1,7 +1,8 @@
class Owner < ActiveRecord::Base
self.primary_key = :owner_id
has_many :pets, -> { order 'pets.name desc' }
has_many :toys, :through => :pets
has_many :toys, through: :pets
has_many :persons, through: :pets
belongs_to :last_pet, class_name: 'Pet'
scope :including_last_pet, -> {

View file

@ -4,6 +4,9 @@ class Pet < ActiveRecord::Base
self.primary_key = :pet_id
belongs_to :owner, :touch => true
has_many :toys
has_many :pet_treasures
has_many :treasures, through: :pet_treasures
has_many :persons, through: :treasures, source: :looter, source_type: 'Person'
class << self
attr_accessor :after_destroy_output

View file

@ -0,0 +1,6 @@
class PetTreasure < ActiveRecord::Base
self.table_name = "pets_treasures"
belongs_to :pet
belongs_to :treasure
end

View file

@ -614,6 +614,12 @@ ActiveRecord::Schema.define do
end
end
create_table :pets_treasures, force: true do |t|
t.column :treasure_id, :integer
t.column :pet_id, :integer
t.column :rainbow_color, :string
end
create_table :pirates, force: true do |t|
t.column :catchphrase, :string
t.column :parrot_id, :integer