-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zad6 - partial #267
base: master
Are you sure you want to change the base?
Zad6 - partial #267
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dzięki za przesłanie rozwiązania 🎉 Niestety nie udało mi się odpalić aplikacji, niżej napisałem w czym może być problem 😉
@@ -0,0 +1,5 @@ | |||
class Category < ApplicationRecord | |||
has_many :products, through: :category_products |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do wcięć używamy 2 spacji
@@ -0,0 +1,5 @@ | |||
class Category < ApplicationRecord | |||
has_many :products, through: :category_products |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brakuje has_many :category_products
@@ -0,0 +1,6 @@ | |||
class Customer < ApplicationRecord | |||
has_many :products, dependent: :destroy #w zasadzie nie obchodzą nas produkty klienta którego usuwamy z bazy chyba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependent
wedle uznania 😄
@@ -0,0 +1,7 @@ | |||
class Product < ApplicationRecord | |||
belongs_to :customer, optional: true | |||
has_many :categories, through: :category_products |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brakuje has_many :category_products
do poprawnego działania 😉
@@ -1,3 +1,6 @@ | |||
Rails.application.routes.draw do | |||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |||
resources :customers do | |||
resources :products |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,4 @@ | |||
class AddEverythingINeed < ActiveRecord::Migration[5.2] | |||
def change | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class CreateCategoryProducts < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :category_products do |t| | ||
add_reference :products, :category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chcemy, żeby w tabeli category_products
znalazły się odniesienia do kategorii i produktów, więc:
t.belongs_to :category, index: true
t.belongs_to :product, index: true
t.datetime "updated_at", null: false | ||
end | ||
|
||
create_table "category_products", force: :cascade do |t| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ta join table jest tak naprawdę pusta, brakuje category_id
i product_id
😉
coś pomyliłem z asocjacjami i nic mi teraz nie chce działać. ale już nie zdążę nic więcej zrobić raczej więc wysyłam częściowe rozwiązanie.