jeudi 17 novembre 2016

How to call active record's association method if we have same menthod name in current model

I am new to Ruby and Rails and I did following code

class Department
end
class Employee
  field :depaertment_id, :default => nil
  belongs_to :department, :autosave => false
  def department
    dept = self.super.department # check whether associated department object exists as per self.department active record's method
    if dept.nil?
      #other operation
    end
  end
end

Here from department method I need get department object

If I do following code then department object is easily available as per rails association

class Employee
 field :depaertment_id, :default => nil
 belongs_to :department, :autosave => false
 def get_department
   dept = self.department 
   if dept.nil?
     #other operation
   end
 end
end

Please help me, How can i get department object Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire