Skip to content

Commit

Permalink
feat: Schema Models Assoc
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Feb 6, 2023
1 parent 0150118 commit 702df56
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/food.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Food < ApplicationRecord
belongs_to :user
has_many :recipe_foods
end
4 changes: 4 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Recipe < ApplicationRecord
belongs_to :user
has_many :recipe_foods
end
4 changes: 4 additions & 0 deletions app/models/recipe_food.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class RecipeFood < ApplicationRecord
belongs_to :recipe
belongs_to :food
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class User < ApplicationRecord
has_many :foods
has_many :recipes
end
9 changes: 9 additions & 0 deletions db/migrate/20230206142054_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20230206142118_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateRecipes < ActiveRecord::Migration[7.0]
def change
create_table :recipes do |t|
t.string :name
t.time :preparationTime
t.time :cookingTime
t.text :description
t.boolean :public
t.references :user, null: false, foreign_key: true

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20230206142713_create_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateFoods < ActiveRecord::Migration[7.0]
def change
create_table :foods do |t|
t.string :name
t.bigint :price
t.bigint :quantity
t.bigint :measurementUnit
t.references :user, null: false, foreign_key: true

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20230206142856_create_recipe_foods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateRecipeFoods < ActiveRecord::Migration[7.0]
def change
create_table :recipe_foods do |t|
t.bigint :quantity
t.references :recipe, null: false, foreign_key: true
t.references :food, null: false, foreign_key: true

t.timestamps
end
end
end
60 changes: 60 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/fixtures/foods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
price:
quantity:
measurementUnit:
user: one

two:
name: MyString
price:
quantity:
measurementUnit:
user: two
11 changes: 11 additions & 0 deletions test/fixtures/recipe_foods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
quantity:
recipe: one
food: one

two:
quantity:
recipe: two
food: two
17 changes: 17 additions & 0 deletions test/fixtures/recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
preparationTime: 2023-02-06 19:21:18
cookingTime: 2023-02-06 19:21:18
description: MyText
public: false
user: one

two:
name: MyString
preparationTime: 2023-02-06 19:21:18
cookingTime: 2023-02-06 19:21:18
description: MyText
public: false
user: two
7 changes: 7 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString

two:
name: MyString
7 changes: 7 additions & 0 deletions test/models/food_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class FoodTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/recipe_food_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RecipeFoodTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/recipe_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RecipeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 702df56

Please sign in to comment.