Forum: Ruby on Rails Override automatic accessor for reference field in model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-02-20 16:00
When a column in a database table is actual data, rather than an fkey to
another table, I can override the automatic accessor by just doing the

def field_name
  # do something here

This does not seem to work for me if the field is an fkey, say user_id,
linking to another table. I've made this work by aliasing the accessor
like this:

alias old_field_name field_name
def field_name
  #do something

This works, but is there a built in function that I need to call to
avoid having to alias this? I've tried calling read_attribute(user_id)
and read_attribute(user) - neither works for me.

This topic is locked and can not be replied to.