diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/cart.rb | 4 | ||||
-rw-r--r-- | app/models/product.rb | 2 | ||||
-rw-r--r-- | app/models/product_cart.rb | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/app/models/cart.rb b/app/models/cart.rb index f9e5ea0..4bccd67 100644 --- a/app/models/cart.rb +++ b/app/models/cart.rb @@ -2,5 +2,7 @@ # Cart class Cart < ApplicationRecord - has_one :user_account + has_one :user_account, dependent: :destroy + has_many :product_carts + has_many :products, through: :product_carts end diff --git a/app/models/product.rb b/app/models/product.rb index b9ca828..c4514a2 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -12,6 +12,8 @@ class Product < ApplicationRecord belongs_to :company has_many :product_reviews + has_many :product_carts + has_many :carts, through: :product_carts validates :name, presence: true validates :unitary_price, presence: true diff --git a/app/models/product_cart.rb b/app/models/product_cart.rb new file mode 100644 index 0000000..10d4a4c --- /dev/null +++ b/app/models/product_cart.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# ProductCart +# quantity: integer +class ProductCart < ApplicationRecord + belongs_to :cart + belongs_to :product +end |