class Log < ActiveRecord::Base

  belongs_to :recipe
  belongs_to :source_recipe, class_name: 'Recipe'
  belongs_to :user

  validates :date, presence: true
  validates :user_id, presence: true
  validates :rating, numericality: { only_integer: true, allow_blank: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 5, message: 'must be an integer between 1 and 5, inclusive' }

  scope :for_user, ->(user) { where(user: user) }
  scope :for_recipe, ->(recipe) { where(source_recipe: recipe) }

  accepts_nested_attributes_for :recipe, update_only: true, allow_destroy: false

end
