upgrade has_many_polymorphs

This commit is contained in:
Reinier Balt 2008-12-21 22:15:57 +01:00
parent 2d11109b8b
commit f97ca2f6af
178 changed files with 132 additions and 108 deletions

View file

@ -1,5 +0,0 @@
class Aquatic::Fish < ActiveRecord::Base
# set_table_name "fish"
# attr_accessor :after_find_test, :after_initialize_test
end

View file

@ -1,7 +0,0 @@
class Aquatic::PupilsWhale < ActiveRecord::Base
set_table_name "little_whale_pupils"
belongs_to :whale, :class_name => "Aquatic::Whale", :foreign_key => "whale_id"
belongs_to :aquatic_pupil, :polymorphic => true
end

View file

@ -1,15 +0,0 @@
# see http://dev.rubyonrails.org/ticket/5935
module Aquatic; end
require 'aquatic/fish'
require 'aquatic/pupils_whale'
class Aquatic::Whale < ActiveRecord::Base
# set_table_name "whales"
has_many_polymorphs(:aquatic_pupils, :from => [:dogs, :"aquatic/fish"],
:through => "aquatic/pupils_whales") do
def a_method
:correct_block_result
end
end
end

View file

@ -1,26 +0,0 @@
require 'extension_module'
class BeautifulFightRelationship < ActiveRecord::Base
set_table_name 'keep_your_enemies_close'
belongs_to :enemy, :polymorphic => true
belongs_to :protector, :polymorphic => true
# polymorphic relationships with column names different from the relationship name
# are not supported by Rails
acts_as_double_polymorphic_join :enemies => [:dogs, :kittens, :frogs],
:protectors => [:wild_boars, :kittens, :"aquatic/fish", :dogs],
:enemies_extend => [ExtensionModule, proc {}],
:protectors_extend => proc {
def a_method
:correct_proc_result
end
},
:join_extend => proc {
def a_method
:correct_join_result
end
}
end

View file

@ -1,9 +0,0 @@
class Canine < ActiveRecord::Base
self.abstract_class = true
def an_abstract_method
:correct_abstract_method_response
end
end

View file

@ -1,5 +0,0 @@
class Cat < ActiveRecord::Base
# STI base class
self.inheritance_column = 'cat_type'
end

View file

@ -1,18 +0,0 @@
require 'canine'
class Dog < Canine
attr_accessor :after_find_test, :after_initialize_test
set_table_name "bow_wows"
def after_find
@after_find_test = true
# puts "After find called on #{name}."
end
def after_initialize
@after_initialize_test = true
end
end

View file

@ -1,10 +0,0 @@
class EatersFoodstuff < ActiveRecord::Base
belongs_to :foodstuff, :class_name => "Petfood", :foreign_key => "foodstuff_id"
belongs_to :eater, :polymorphic => true
def before_save
self.some_attribute = 3
end
end

View file

@ -1,4 +0,0 @@
class Frog < ActiveRecord::Base
end

View file

@ -1,3 +0,0 @@
class Kitten < Cat
# has_many :eaters_parents, :dependent => true, :as => 'eater'
end

View file

@ -1,4 +0,0 @@
class Parentship < ActiveRecord::Base
belongs_to :parent, :class_name => "Person", :foreign_key => "parent_id"
belongs_to :kid, :polymorphic => true, :foreign_type => "child_type"
end

View file

@ -1,9 +0,0 @@
require 'parentship'
class Person < ActiveRecord::Base
has_many_polymorphs :kids,
:through => :parentships,
:from => [:people],
:as => :parent,
:polymorphic_type_key => "child_type",
:conditions => "people.age < 10"
end

View file

@ -1,39 +0,0 @@
# see http://dev.rubyonrails.org/ticket/5935
require 'eaters_foodstuff'
require 'petfood'
require 'cat'
module Aquatic; end
require 'aquatic/fish'
require 'dog'
require 'wild_boar'
require 'kitten'
require 'tabby'
require 'extension_module'
require 'other_extension_module'
class Petfood < ActiveRecord::Base
set_primary_key 'the_petfood_primary_key'
has_many_polymorphs :eaters,
:from => [:dogs, :petfoods, :wild_boars, :kittens,
:tabbies, :"aquatic/fish"],
# :dependent => :destroy, :destroy is now the default
:rename_individual_collections => true,
:as => :foodstuff,
:foreign_key => "foodstuff_id",
:ignore_duplicates => false,
:conditions => "NULL IS NULL",
:order => "eaters_foodstuffs.updated_at ASC",
:parent_order => "petfoods.the_petfood_primary_key DESC",
:parent_conditions => "petfoods.name IS NULL OR petfoods.name != 'Snausages'",
:extend => [ExtensionModule, OtherExtensionModule, proc {}],
:join_extend => proc {
def a_method
:correct_join_result
end
},
:parent_extend => proc {
def a_method
:correct_parent_proc_result
end
}
end

View file

@ -1,2 +0,0 @@
class Tabby < Cat
end

View file

@ -1,3 +0,0 @@
class WildBoar < ActiveRecord::Base
end