# How to handle reserved names in legacy database

**URL:** <https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930>\
**Category:** Rails\
**Created:** [July 9, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930 "2007-07-09T17:07:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 9, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/1 "2007-07-09T17:07:17Z")

</div>

Hi,

I’m using RoR to interface to a legacy database.

One of the columns in the legacy database is ‘notify’ and this is  
causing (I believe) errors like:

> > r = RegressionData.find(:first)  
> > =\> #\<RegressionData ID: 1, … , user: “”, priority: “”, notify:  
> > “”, …\>
> 
> > r.id  
> > =\> 1
> 
> > r.save  
> > ArgumentError: wrong number of arguments (1 for 0)  
> > from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3.7116/lib/  
> > active\_record/callbacks.rb:332:in `notify' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3.7116/lib/ active_record/callbacks.rb:332:in`callback’  
> > from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3.7116/lib/  
> > active\_record/callbacks.rb:299:in `valid?' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3.7116/lib/ active_record/validations.rb:847:in`save\_without\_transactions’  
> > …

I believe that the notify column is being invoked rather than the  
expected notify method on line 332 of callbacks.rb

Is there a way around this?

I couldn’t find a solution that had been posted for this particular  
column name, though others have reported similar issues and in most  
cases the answer was to rename the column. Not an option in this case.

Thanks,

Allan

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 10, 2007, 1:01pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/2 "2007-07-10T13:01:12Z")

</div>

Anybody got any ideas?

Allan

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 11, 2007, 11:48am UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/3 "2007-07-11T11:48:23Z")

</div>

This hack seems to work:

class LegacyData \< ActiveRecord::Base  
def notify(\*rest)

# puts “notify(#{rest}) called”

```
if rest.length > 0
  super
else
  attributes['notify']
end

```

end  
end

Allan

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 11, 2007, 11:52am UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/4 "2007-07-11T11:52:23Z")

</div>

Allan wrote:

> end  
> end

Cute!

Now also provide def notify=

(And maybe we could meta-program that into acts\_as\_legacy :notify 😉

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 11, 2007, 12:22pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/5 "2007-07-11T12:22:26Z")

</div>

Hi –

On Wed, 11 Jul 2007, Phlip wrote:

> > else  
> > attributes[‘notify’]  
> > end  
> > end  
> > end
> 
> Cute!
> 
> Now also provide def notify=

I don’t think there’s a notify= name clash (though I haven’t checked  
it fully).

David

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 11, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/6 "2007-07-11T12:36:00Z")

</div>

dblack wrote:

> > Now also provide def notify=
> 
> I don’t think there’s a notify= name clash (though I haven’t checked  
> it fully).

I realized that just after my post.

I guess this reflects my C++ training - overload operators in coherent  
bunches, not one at a time…

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 12, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/7 "2007-07-12T12:27:53Z")

</div>

On Jul 11, 11:34 am, “Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> dblack wrote:
> 
> > > Now also provide def notify=
> 
> > I don’t think there’s a notify= name clash (though I haven’t checked  
> > it fully).
> 
> I realized that just after my post.
> 
> I guess this reflects my C++ training - overload operators in coherent  
> bunches, not one at a time…

I agree with those sentiments about coherency, which is why I call it  
a hack, there are undoubtedly other keywords that should be treated in  
this way, I’ve ‘solved’ it for the notify method, but what about  
others where the method signature is identical - i.e. the method takes  
no arguments? I don’t think this hack works for those methods.

There does seem to be a way to prevent attribute read, query and write  
methods being set but it’s a global switch, so affects all  
ActiveRecord objects, which is not all that useful 'cos having the  
attribute methods is very useful on non-legacy tables!

I dug around the AR:Base code but couldn’t quite work out where the  
attribute methods were being introduced or if the method where it was  
done could be overriden. Maybe I’ll see if a plugin would be able to  
do this - act\_as\_dumb\_orm\_model maybe?

Allan

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 13, 2007, 6:27am UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/8 "2007-07-13T06:27:07Z")

</div>

On 7/12/07, Allan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There does seem to be a way to prevent attribute read, query and write  
> methods being set but it’s a global switch, so affects all  
> ActiveRecord objects, which is not all that useful 'cos having the  
> attribute methods is very useful on non-legacy tables!
> 
> I dug around the AR:Base code but couldn’t quite work out where the  
> attribute methods were being introduced or if the method where it was  
> done could be overriden. Maybe I’ll see if a plugin would be able to  
> do this - act\_as\_dumb\_orm\_model maybe?

Hi Allan,

#generate\_read\_methods is actually queried on the ActiveRecord::Base  
subclass, so you can specify it on a per class (or per class  
heirarchy) basis.

If you want to try “monkey-patching” or something, those methods are  
created in ActiveRecord::Base#define\_read\_methods (in base.rb).

Hope this helps,  
George.

---

<div class="post-metadata">

**Author:** ![Allan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Allan](https://www.ruby-forum.com/u/Allan)\
**Post date:** [July 15, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/how-to-handle-reserved-names-in-legacy-database/108930/9 "2007-07-15T22:21:19Z")

</div>

On Jul 13, 5:26 am, George [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > attribute methods were being introduced or if the method where it was  
> > done could be overriden. Maybe I’ll see if a plugin would be able to  
> > do this - act\_as\_dumb\_orm\_model maybe?
> 
> Hi Allan,
> 
> #generate\_read\_methods is actually queried on the ActiveRecord::Base  
> subclass, so you can specify it on a per class (or per class  
> heirarchy) basis.

Ah, thanks, re-looked at that and it does seem to work, in irb at  
least, I originally thought it was a global setting and dismissed it.

I set it in environment.rb and all seemed fine, thanks again.

MyLegacyClass.generate\_read\_methods = false

Allan
