# Override \[\] and \[\]= on an ActiveRecord

**URL:** <https://www.ruby-forum.com/t/override-and-on-an-activerecord/152994>\
**Category:** Rails\
**Created:** [November 10, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/override-and-on-an-activerecord/152994 "2008-11-10T23:22:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 10, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/override-and-on-an-activerecord/152994/1 "2008-11-10T23:22:08Z")

</div>

Okay, I finally figured out what was going on with my mysterious  
migrate-to-Rails2 problem.

In Rails 1.x, I got away with over-riding [] and []= on an  
ActiveRecord::Base model class. This made for some very convenient  
coding, which is now littered all over my application.

In Rails2, you apparently can’t do this.

Should I assume this is right, rather than a bug? Should it be  
documented anywhere?

Still trying to think through the best least painful way to refactor my  
code.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [November 10, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/override-and-on-an-activerecord/152994/2 "2008-11-10T23:47:45Z")

</div>

On 10 Nov 2008, at 22:22, Jonathan R. wrote:

> Should I assume this is right, rather than a bug? Should it be  
> documented anywhere?

[]and []= have (as far as I can remember) allowed you to access  
attributes (and are documented as such). Overriding public AR methods  
is always going to be risky as you may not be the only using them -  
Active Record itself may well be using them.

> Still trying to think through the best least painful way to refactor  
> my  
> code.  
> What was your definition of []/[]= ?

Fred
