On Jul 10, 2007, at 1:51 AM, Allan wrote: > trying to use RoR in an enterprise setting (i.e. with legacy > databases) and am having problems with AR objects where a db column > has the same name as a RoR reserved word, 'notify' in this case. > > How do I get round the issue? Renaming the column is not an option > since other applications are also using the database. > > I thought about stifling RoR feature where it generates the read > methods (e.g. notify(), notify=() and notify?() )for each column name > and can see that these ought not to be generated when > ActiveRecord::Base.generate_read_methods is false but I don't really > want to do this for all models, only those with legacy databases. > > Any ideas? > > Allan
You can use the attributes hash to access the columns (model[:notify] works too), and create getter/setter methods like notify_column() and notify_column=() to get around the naming clash. The ActiveRecord::Base API lives in the same namespace as the attributes of model classes. That means there can be occasional clashes. One way to deal with that is to always enforce a separation of namespaces, but that makes the API more heavyweight. ActiveRecord strikes a pretty good balance between making the API lightweight, and allowing you a second way to access attributes when there are name clashes. By the way, this list is not for support issues. Those should be sent to [EMAIL PROTECTED] -- Josh Susser http://blog.hasmanythrough.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
