Hi, 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
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? > > AllanYou 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 rubyonrails-talk@googlegroups.com. -- 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 10, 2:29 pm, Josh Susser <j...@hasmanythrough.com> wrote:> On Jul 10, 2007, at 1:51 AM, Allan wrote:> 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.True, but I don''t even want to touch the notify column, the problem happens when I access another column/attribute and then try to save the record. The Model#notify method is created as soon as I touch the model in any way (even just to re-save it w/o any changes in attributes) and it''s during the save process that the Model#notify method is called, this time with an argument which, of course is a problem since the notify method is now defined with no arguments:>> r=RegressionData.find(:first)=> #<RegressionData ID: 681, status: "N/A", notify: "", num_wpnts: 0, num_bpnts: 0>>> r.saveArgumentError: 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'' ... So without touching the object I cannot save it.> > 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.I''d like AR to allow me to turn off the possibility of clashing (on certain models :-) and only be able to use the second way to access attributes.> > By the way, this list is not for support issues. Those should be sent > to rubyonrails-talk@googlegroups.com.I appreciate that point and your response to my point. Is this not a core issue to legacy database support though? BTW, nobody has made any comment to the same issue posted on the rubyonrails-talk group, I guess it''s just me being dumb or unlucky! Thanks, Allan> -- > Josh Susserhttp://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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---