Created
April 18, 2020 03:26
-
-
Save fuzz/2ab0fa80fa755e8374f4e95f425269bb to your computer and use it in GitHub Desktop.
Offerings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# migration | |
class CreateOfferings < ActiveRecord::Migration[6.0] | |
def change | |
create_table :offerings do |t| | |
t.references :product, foreign_key: true | |
t.references :vendor, foreign_key: true | |
# add other unique-to-vendor fields/associations | |
t.timestamps | |
end | |
end | |
end | |
# offering model | |
class Offering < ApplicationRecord | |
belongs_to :product | |
belongs_to :vendor | |
end | |
# product model | |
class Product < ApplicationRecord | |
has_many :offerings, dependent: :destroy | |
has_many :vendors, through: :offerings | |
end | |
# vendor model | |
class Vendor < ApplicationRecord | |
has_many :offerings, dependent: :destroy | |
has_many :products, through: :offerings | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment