Skip to content

Instantly share code, notes, and snippets.

@gabidavila
Created August 5, 2017 19:48
Show Gist options
  • Save gabidavila/0558ded46d656a4a0b948357b99c6e9f to your computer and use it in GitHub Desktop.
Save gabidavila/0558ded46d656a4a0b948357b99c6e9f to your computer and use it in GitHub Desktop.
### app/models/boat.rb ###
class Boat < ActiveRecord::Base
belongs_to :captain
has_many :boat_classifications
has_many :classifications, through: :boat_classifications
end
### app/models/captain.rb ###
class Captain < ActiveRecord::Base
has_many :boats
end
### app/models/boat_classification.rb ###
class BoatClassification < ActiveRecord::Base
belongs_to :boat
belongs_to :classification
end
### app/models/classification.rb ###
class Classification < ActiveRecord::Base
has_many :boat_classifications
has_many :boats, through: :boat_classifications
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment