Keith Lancaster
2006-Feb-20 15:00 UTC
[Rails] Override automatic accessor for reference field in model
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 following: def field_name # do something here read_attribute(field_name) end 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 old_field_name end 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. TIA, Keith -- Posted via http://www.ruby-forum.com/.