Wip: bookmark statuses view and adder
This commit is contained in:
parent
f6bdd9b6de
commit
87490a3220
30 changed files with 616 additions and 24 deletions
34
app/models/bookmark_category_status.rb
Normal file
34
app/models/bookmark_category_status.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: bookmark_category_statuses
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# bookmark_category_id :bigint(8) not null
|
||||
# status_id :bigint(8) not null
|
||||
# bookmark_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class BookmarkCategoryStatus < ApplicationRecord
|
||||
belongs_to :bookmark_category
|
||||
belongs_to :status
|
||||
belongs_to :bookmark
|
||||
|
||||
validates :status_id, uniqueness: { scope: :bookmark_category_id }
|
||||
validate :validate_relationship
|
||||
|
||||
before_validation :set_bookmark
|
||||
|
||||
private
|
||||
|
||||
def set_bookmark
|
||||
self.bookmark = Bookmark.find_by!(account_id: bookmark_category.account_id, status_id: status_id)
|
||||
end
|
||||
|
||||
def validate_relationship
|
||||
errors.add(:account_id, 'bookmark relationship missing') if bookmark_id.blank?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue