added tags schema and model
This commit is contained in:
parent
e758af25b2
commit
45b0a9c7b1
@ -4,6 +4,8 @@ class Recipe < ApplicationRecord
|
||||
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
||||
belongs_to :user
|
||||
|
||||
has_and_belongs_to_many :tags
|
||||
|
||||
scope :undeleted, -> { where('deleted <> ? OR deleted IS NULL', true) }
|
||||
scope :not_log, -> { where('is_log <> ? OR is_log IS NULL', true) }
|
||||
scope :active, -> { undeleted.not_log }
|
||||
|
5
app/models/tag.rb
Normal file
5
app/models/tag.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class Tag < ApplicationRecord
|
||||
|
||||
validates :name, presence: true, length: {maximum: 250}, uniqueness: { case_sensitive: false }
|
||||
|
||||
end
|
14
db/migrate/20161014173138_create_tags.rb
Normal file
14
db/migrate/20161014173138_create_tags.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class CreateTags < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :tags do |t|
|
||||
t.string :name, index: {unique: true}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :recipes_tags, id: false do |t|
|
||||
t.integer :recipe_id, index: true
|
||||
t.integer :tag_id, index: true
|
||||
end
|
||||
end
|
||||
end
|
5
spec/factories/tags.rb
Normal file
5
spec/factories/tags.rb
Normal file
@ -0,0 +1,5 @@
|
||||
FactoryGirl.define do
|
||||
factory :tag do
|
||||
name "MyString"
|
||||
end
|
||||
end
|
5
spec/models/tag_spec.rb
Normal file
5
spec/models/tag_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Tag, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue
Block a user