11#*******************************************************************************
22# For testing basic associations.
33#*******************************************************************************
4+ class ApplicationRecord < ActiveRecord ::Base
5+ self . abstract_class = true
6+ end
47
5- class Pet < ActiveRecord :: Base
8+ class Pet < ApplicationRecord
69 has_many :toys
710 has_one :pet_tag
811 has_one :pet_profile
@@ -13,23 +16,23 @@ class Pet < ActiveRecord::Base
1316 has_many :pet_sitters , through : :pet_sitting_patronages
1417end
1518
16- class Toy < ActiveRecord :: Base
19+ class Toy < ApplicationRecord
1720 validates :name , length : { minimum : 3 }
1821 belongs_to :pet
1922end
2023
21- class PetTag < ActiveRecord :: Base
24+ class PetTag < ApplicationRecord
2225 belongs_to :pet
2326end
2427
25- class PetFood < ActiveRecord :: Base
28+ class PetFood < ApplicationRecord
2629 # Rails 3 expects the join table to be called pet_foods_pets
2730 # Rails 4 expects the join table to be called pet_foods_pets
2831 # We explicitly name the join table so that this code works with both Rails 3 and Rails 4.
2932 has_and_belongs_to_many :pets , join_table : 'pet_foods_pets'
3033end
3134
32- class Agency < ActiveRecord :: Base
35+ class Agency < ApplicationRecord
3336 has_many :pet_sitters
3437end
3538
@@ -40,42 +43,42 @@ class Kind < ActiveHash::Base
4043 ]
4144end
4245
43- class PetSitter < ActiveRecord :: Base
46+ class PetSitter < ApplicationRecord
4447 extend ActiveHash ::Associations ::ActiveRecordExtensions
4548 belongs_to :kind
4649 belongs_to :agency
4750 has_many :pet_sitting_patronages
4851 has_many :pets , through : :pet_sitting_patronages
4952end
5053
51- class PetSittingPatronage < ActiveRecord :: Base
54+ class PetSittingPatronage < ApplicationRecord
5255 belongs_to :pet
5356 belongs_to :pet_sitter
5457end
5558
56- class PetProfile < ActiveRecord :: Base
59+ class PetProfile < ApplicationRecord
5760 belongs_to :pet
5861 has_one :address
5962end
6063
61- class Address < ActiveRecord :: Base
64+ class Address < ApplicationRecord
6265 belongs_to :pet_profile
6366end
6467
6568#*******************************************************************************
6669# For testing polymorphic associations and custom-named foreign keys.
6770#
6871
69- class Picture < ActiveRecord :: Base
72+ class Picture < ApplicationRecord
7073 belongs_to :imageable , polymorphic : true
7174 belongs_to :album , foreign_key : 'picture_album_id'
7275end
7376
74- class Product < ActiveRecord :: Base
77+ class Product < ApplicationRecord
7578 has_many :pictures , as : :imageable
7679end
7780
78- class Album < ActiveRecord :: Base
81+ class Album < ApplicationRecord
7982 has_many :pictures , foreign_key : 'picture_album_id'
8083end
8184
@@ -85,22 +88,22 @@ class Album < ActiveRecord::Base
8588# # For testing denormalized data structures.
8689# #
8790
88- # class Owner < ActiveRecord::Base
91+ # class Owner < ApplicationRecord
8992# has_many :vehicles
9093# has_many :amenities # this is not normalized, you wouldn't normally do this
9194# end
9295
93- # class Vehicle < ActiveRecord::Base
96+ # class Vehicle < ApplicationRecord
9497# has_many :amenities
9598# belongs_to :owner
9699# end
97100
98- # class Amenity < ActiveRecord::Base
101+ # class Amenity < ApplicationRecord
99102# belongs_to :vehicle
100103# belongs_to :owner # this is not normalized, you wouldn't normally do this
101104# has_one :warranty
102105# end
103106
104- # class Warranty < ActiveRecord::Base
107+ # class Warranty < ApplicationRecord
105108# belongs_to :amenity
106109# end
0 commit comments