summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-04 20:08:37 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-04 20:08:37 -0600
commit96ce018912ceffb7270b883a8982b1e2403cda1c (patch)
tree7a427516c30f52f0d121e9bc31ae952a8713351b /app
parent18b129f8f6ba8c5c98adaf82ccfc4ba38264a29b (diff)
Añade modelo ProductCart
Diffstat (limited to 'app')
-rw-r--r--app/models/cart.rb4
-rw-r--r--app/models/product.rb2
-rw-r--r--app/models/product_cart.rb8
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