class Song < ApplicationRecord
    belongs_to :user, optional: true  
    has_many :verses 
    has_many :genres, through: :verses 
    accepts_nested_attributes_for :verses#, reject_if: :blank 
    accepts_nested_attributes_for :genres# reject_if: :not_selected
    after_initialize :set_defaults, unless: :persisted?
    validates_associated :verses,:genres

    scope :title_like, ->(title) { where("title like ?",title)}


    def blank(attr)
        attr[:content].blank?
    end

    def not_selected(attr)
        attr[:name].blank?
    end
    
    def set_defaults
        self.title  ||= 'Untitled'
    end
    
    

end
