Skip to content

Instantly share code, notes, and snippets.

@tonyfg
Created September 14, 2018 09:40
Show Gist options
  • Save tonyfg/61b69391aa139be825300a59fe4506c0 to your computer and use it in GitHub Desktop.
Save tonyfg/61b69391aa139be825300a59fe4506c0 to your computer and use it in GitHub Desktop.
Org list models
# app/models/organization.rb
class Organization < ApplicationRecord
has_many :hqs
has_many :stores, through: :hqs
end
# app/models/country.rb
class Country < ApplicationRecord
end
# app/models/hq.rb
class Hq < ApplicationRecord
belongs_to :organization
belongs_to :country
has_many :stores
end
# app/models/store.rb
class Store < ApplicationRecord
belongs_to :hq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment