# Overriding reflected AR attributes

**URL:** <https://www.ruby-forum.com/t/overriding-reflected-ar-attributes/117150>\
**Category:** Rails\
**Created:** [October 13, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/overriding-reflected-ar-attributes/117150 "2007-10-13T23:15:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 13, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/overriding-reflected-ar-attributes/117150/1 "2007-10-13T23:15:44Z")

</div>

OK, so I get ActiveRecord determines model attributes through  
reflection of the table schema. Handy for many cases, but not mine.

I need to override that and provide my own mapping of attribute names  
(for use in all app-specific code) to column names.

I’ve been poking around looking for how that might be done like I see  
table\_name and other attributes can be, but so far I’m coming up empty.

I’ve written/been using my own framework for years in another  
language that handled all this (more of a table gateway than an  
ActiveRecord pattern), so I can do it, just wondering if Rails has  
it, and if not, what’s the best, i.e. Ruby/Rails “right way” to add  
it (extend AR modules? write a super class for all my models? write a  
utility class for all my models to use, other?)

(For those of you that want to know why, I can elaborate, but I’ll  
spare us the bulk until needed.)

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 14, 2007, 5:12am UTC](https://www.ruby-forum.com/t/overriding-reflected-ar-attributes/117150/2 "2007-10-14T05:12:52Z")

</div>

you could just write a getter/setter for each custom attr to point  
back to the reflected attr:

class MyClass \< ActiveRecord::Base  
def my\_foo  
self[:foo]  
end

def my\_foo=(val)  
self[:foo] = val  
end  
end
