On Nov 28, 6:30 am, Kevin <[email protected]> wrote:
> I don't have control over the underlying database schema I'm working
> with.  The column names are not very intuitive so I'd like to simplify
> my models using more human friendly names.  For example I'd like to
> access column values with symbols like ':email_address' instead of
> ':corp_usr_email_addr_txt').  Is this possible?
>
> I've searched the docs, discussions, and code for this... so if I
> missed the answer it was not for lack of trying.
>
> Thanks,
> Kevin

With models you can do:

  class Album < Sequel::Model
    def self.column_aliases(hash)
      hash.each do |k,v|
        define_method(k){send(v)}
        define_method(:"#{k}="){|x| send(:"#{v}=", x)}
      end
    end
    column_aliases :email_address => :corp_usr_email_addr_txt
  end

You will have to use the real column names as arguments to dataset
methods such as filter, but the above code will allow you to use the
friendly names for column getters and setters.

It's possible to use friendly symbols in dataset methods, but it
requires an ugly hack.

Jeremy

--

You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en.


Reply via email to