Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Zad6 - partial #267

wants to merge 4 commits into from

Conversation

czaaaaaja
Copy link

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.

@ahawrylak ahawrylak added the zad6 label Dec 11, 2018
@ahawrylak ahawrylak self-assigned this Dec 11, 2018
Copy link
Collaborator

@ahawrylak ahawrylak left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zauważ, że niesprecyzowanie konkretnych akcji(resources :customers, only: :index) powoduje powstanie masy niepotrzebnych i niezaimplementowanych ścieżek:
screen shot 2018-12-11 at 15 38 42

@@ -0,0 +1,4 @@
class AddEverythingINeed < ActiveRecord::Migration[5.2]
def change
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty

class CreateCategoryProducts < ActiveRecord::Migration[5.2]
def change
create_table :category_products do |t|
add_reference :products, :category
Copy link
Collaborator

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|
Copy link
Collaborator

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 😉

@ahawrylak ahawrylak added the ✓ Done in the summary it is considered as done label Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✓ Done in the summary it is considered as done zad6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants