Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Nonoptimal many-to-many associations
- #app/models/train.rb
- class Train < ActiveRecord::Base
- has_many :train_locations, dependent: :destroy
- has_many :locations, through: :train_locations
- end
- #app/models/train_location.rb
- class TrainLocation < ActiveRecord::Base
- belongs_to :train
- belongs_to :location
- end
- #app/models/copter.rb
- class Copter < ActiveRecord::Base
- has_many :copter_locations, dependent: :destroy
- has_many :locations, through: :copter_locations
- end
- #app/models/copter_location.rb
- class CopterLocation < ActiveRecord::Base
- belongs_to :copter
- belongs_to :location
- end
- #app/models/truck.rb
- class Truck < ActiveRecord::Base
- has_many :truck_locations, dependent: :destroy
- has_many :locations, through: :truck_locations
- end
- #app/models/truck_location.rb
- class TruckLocation < ActiveRecord::Base
- belongs_to :truck
- belongs_to :location
- end
- #app/models/ship.rb
- class Ship < ActiveRecord::Base
- has_many :ship_locations, dependent: :destroy
- has_many :locations, through: :ship_locations
- end
- #app/models/ship_location.rb
- class ShipLocation < ActiveRecord::Base
- belongs_to :ship
- belongs_to :location
- end
- #app/models/location.rb
- class Location < ActiveRecord::Base
- has_many :train_locations, dependent: :destroy
- has_many :copter_locations, dependent: :destroy
- has_many :truck_locations, dependent: :destroy
- has_many :ship_locations, dependent: :destroy
- has_many :trains, :through => :train_locations
- has_many :copters, :through => :copter_locations
- has_many :trucks, :through => :truck_locations
- has_many :ships, :through => :ship_locations
- end
Advertisement
Add Comment
Please, Sign In to add comment