The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Legacy Polymorphic Associations

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Amos King is a Web Developer for the US Postal Service and for Ramped Media.
Legacy Polymorphic Associations Posted: Dec 10, 2008 9:43 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Amos King.
Original Post: Legacy Polymorphic Associations
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Amos King
Latest Posts From DirtyInformation

Advertisement

Did I mention I hate legacy databases.

I'm working on a legacy project that uses a polymophic associations where the type column is lower case. The thing that sucks is I can't change the database because I still have an untested Java side that we don't want to change. So here comes the solution, and maybe some flames.

ActiveRecord::AttributeMethods#read_attribute is called on the type field, which we will call foo, because it isn't called type in our database. So in our model we have this:

#Disclaimer
def read_attribute(attr_name)
  if attr_name == 'foo'
    #code to change to accepted type column values
    foo.camelize
  else
    super
  end
end

Read: Legacy Polymorphic Associations

Topic: Targeted Languages Previous Topic   Next Topic Topic: Little Known Ways to Ruby Mastery by Chris Matthieu

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use