rails override default getter for a relationship (belongs_to)

Solution 1:

alias_method is your friend here.

alias_method :original_bar, :bar
def bar
  self.original_bar || Bar.last
end

The way this works is that you alias the default "bar" method as "original bar" and then implement your own version of "bar". If the call to original_bar returns nil then you return the last Bar instance instead.

Solution 2:

i found that using "super" is the best way

def bar
  super || Bar.last
end

I hope this helps you :D