Active Record with Delegate and conditions

Viewed 13511

Is it possible to use delegate in your Active Record model and use conditions like :if on it?

class User < ApplicationRecord
  delegate :company, :to => :master, :if => :has_master?

  belongs_to :master, :class_name => "User"

  def has_master?
    master.present?
  end
end
2 Answers
Related