Thanks, I'll consider that. It has pluses and minuses. I like that
I can not have to use the constant-like identifiers throughout code.
On the other hand having scattered accessors and even sql finder code
referencing things that aren't actually in the database might be
a somewhat high price to pay in terms of principle. I try to stay
away from abstractions that obscure reality as much as possible.
There are times when it's worth it many times over, so I need to think
about whether this is one of those or not.
Thanks for the idea though, I didn't know about that!
-glenn
Jordan Fowler wrote:
> The easiest thing to do by far is to set up an attribute alias. In your
> code you can just reference the alias and under the hood it will do all
> necessary conversion; this even works with queries. With your use case,
> see below:
>
> class ForeignTable < ActiveRecord::Base
> alias_attribute :Last_Name, :last_name
> end
>
> This means you'll only ever need to mention "Last_Name" once in your
> code. You can do things like this:
>
> ForeignTable.find(:all, :conditions => {:last_name => 'Little'})
>
> Cheers,
> Jordan
>
> On Mar 16, 2009, at 4:18 PM, Glenn Little wrote:
>
>>
>> We've just run into a situation where an outside database we talk to has
>> changed its schema for one of its tables. Among the potential issues
>> is that a bunch of the column names now start with capital letters.
>>
>> Changing our references accordingly *seems* to work. ActiveRecord
>> is now giving us
>>
>> ForeignTable#Last_Name()
>>
>> instead of
>>
>> ForeignTable#last_name.
>>
>> But I noticed that the IDE is now treating Last_Name like a constant
>> (because of the initial cap) and I got to wondering if we weren't going
>> to be shooting ourselves in the foot somewhere down the line by naming
>> our ActiveRecord model objects using the conventions normally used for
>> contants.
>>
>> Note that this database is not in our control, so we can't do anything
>> about the name changes.
>>
>> Any caveats or issues with this that I may be missing, or maybe a way
>> to tell ActiveRecord to ignore capitalization for a given table?
>>
>> Thanks...
>>
>> -glenn
>>
>>
>>
>>
>
>
>
> ---------------------------------------------------------------
>
> Jordan A. Fowler
> 2928 Fir St.
> San Diego, CA 92102
> E-mail: [email protected] <mailto:[email protected]>
> Website: http://www.jordanfowler.com
> Phone: (619) 339-6752
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---