Add posts, tags, tagging, to database. Create references to align with new DB model. Add image of mermaid template model.
This commit is contained in:
parent
4edae5e7bb
commit
8ee5dd9322
17 changed files with 154 additions and 2 deletions
|
|
@ -1,5 +1,8 @@
|
|||
class Image < ApplicationRecord
|
||||
has_one_attached :file
|
||||
|
||||
has_many :taggings, as: :taggable
|
||||
has_many :tags, through: :taggings
|
||||
|
||||
validates :title, :file, presence: true
|
||||
end
|
||||
|
|
|
|||
6
app/models/post.rb
Normal file
6
app/models/post.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class Post < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :image
|
||||
has_many :taggings, as: :taggable
|
||||
has_many :tags, through: :taggings
|
||||
end
|
||||
5
app/models/tag.rb
Normal file
5
app/models/tag.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Tag < ApplicationRecord
|
||||
has_many :taggings
|
||||
has_many :posts, through: :taggings, source: :taggable, source_type: "Post"
|
||||
has_many :images, through: :taggings, source: :taggable, source_type: "Image"
|
||||
end
|
||||
4
app/models/tagging.rb
Normal file
4
app/models/tagging.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class Tagging < ApplicationRecord
|
||||
belongs_to :tag
|
||||
belongs_to :taggable, polymorphic: true
|
||||
end
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :posts
|
||||
|
||||
validates :name, :status, :email, :password_digest, presence: true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue