OK, so I get that ActiveRecord determines model attributes through reflection of the table schema. Handy for many cases, but not mine. I need to override that and provide my own mapping of attribute names to column names to use the mapped names throughout the application code. I''ve been poking around looking for where in AR''s hierarchy I can can inject this mapping, but so far I''m coming up empty. I''ve written/been using my own framework for years in another language that handled all this (more of a table gateway than an ActiveRecord pattern), so I can do it, just wondering if Rails has it, and if not, what''s the best, i.e. Ruby/Rails "right way" to add it (extend AR modules? write a super class between AR and all my models? Write a utility class for all my models to use, other?) For those of you that want to know why, the reaons boil down to adapting to legacy data (same "News module" code used over & over to adapt to existing news data), and same code being used to aggregate multiple data sources. IN both cases the mapper abstracts the real data source so the attributes of the app code can remain a familiar constant. (yes I posted this a couple days ago, but it was a weekend, thought I might have more luck on a weekday :-) TIA. -- gw --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Greg, If I''m understanding perhaps the alias_attribute method will give you some ideas? { :title => :name, :synopsis => :description, :short_synopsis => :short_description, :quantity_sold => :quantity_ordered }.each { |aliased, actual| alias_attribute aliased, actual } Good luck! Tim On Oct 16, 12:24 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> OK, so I get that ActiveRecord determines model attributes through > reflection of the table schema. Handy for many cases, but not mine. > > I need to override that and provide my own mapping of attribute names > to column names to use the mapped names throughout the application code. > > I''ve been poking around looking for where in AR''s hierarchy I can can > inject this mapping, but so far I''m coming up empty. > > I''ve written/been using my own framework for years in another > language that handled all this (more of a table gateway than an > ActiveRecord pattern), so I can do it, just wondering if Rails has > it, and if not, what''s the best, i.e. Ruby/Rails "right way" to add > it (extend AR modules? write a super class between AR and all my > models? Write a utility class for all my models to use, other?) > > For those of you that want to know why, the reaons boil down to > adapting to legacy data (same "News module" code used over & over to > adapt to existing news data), and same code being used to aggregate > multiple data sources. IN both cases the mapper abstracts the real > data source so the attributes of the app code can remain a familiar > constant. > > (yes I posted this a couple days ago, but it was a weekend, thought I > might have more luck on a weekday :-) > > TIA. > > -- gw--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmm, doesn''t show up in the RDocs, but I found some blogs on it. Looks like that will be the place to start. Cool. thank you. -- gw On Oct 16, 2007, at 8:10 PM, tmac wrote:> If I''m understanding perhaps the alias_attribute method will give you > some ideas? > > { :title => :name, > :synopsis => :description, > :short_synopsis => :short_description, > :quantity_sold => :quantity_ordered > }.each { |aliased, actual| alias_attribute aliased, actual } > > Good luck! > Tim > > On Oct 16, 12:24 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: >> OK, so I get that ActiveRecord determines model attributes through >> reflection of the table schema. Handy for many cases, but not mine. >> >> I need to override that and provide my own mapping of attribute names >> to column names to use the mapped names throughout the application >> code. >> >> I''ve been poking around looking for where in AR''s hierarchy I can can >> inject this mapping, but so far I''m coming up empty. >> >> I''ve written/been using my own framework for years in another >> language that handled all this (more of a table gateway than an >> ActiveRecord pattern), so I can do it, just wondering if Rails has >> it, and if not, what''s the best, i.e. Ruby/Rails "right way" to add >> it (extend AR modules? write a super class between AR and all my >> models? Write a utility class for all my models to use, other?) >> >> For those of you that want to know why, the reaons boil down to >> adapting to legacy data (same "News module" code used over & over to >> adapt to existing news data), and same code being used to aggregate >> multiple data sources. IN both cases the mapper abstracts the real >> data source so the attributes of the app code can remain a familiar >> constant. >> >> (yes I posted this a couple days ago, but it was a weekend, thought I >> might have more luck on a weekday :-) >> >> TIA.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---