On Thursday, July 17, 2014 10:08:32 AM UTC-7, Richard Michael wrote:
>
> Hello,
>
> I am new to Sequel, it is fantastic, thank you!
>
> I have a database schema which uses CamelCase for most names, both tables
> and columns. I am using `def_column_alias` to provide Ruby-like method
> names:
>
> class Foo < S::M
> def_column_alias :email_address, :EmailAddress # ==> a_foo.email_address
>
> # many more such def_c_a calls
> end
>
>
> However, I'd like to do a little more than simple CamelCase to snake_case
> conversion. For example, many column names are [more or less] prefixed
> with the table name (ex. table: Folders with columns: FolderName, FolderId)
> and I'd like to remove the prefix.
>
>
> How can I ask Sequel to define these aliases (or methods) when it builds
> the usual methods (#EmailAddress)?
>
> I've searched the mailing list and seen discussion (in 2011) about
> overriding Sequel::Model::Base#def_column_accessor. I'm cautious about
> overriding -- is that still a reasonable approach? Perhaps I should be
> looking for a specific hook, or writing a plugin?
>
> I'd appreciate someone nudging me in the right direction.
>
I think defining Sequel::Model.def_column_accessor is probably fine. Just
call super first:
def (Sequel::Model).def_column_accessor(*columns)
super
columns.each |c|
def_column_alias(alias_method_for(c), c)
end
end
You'll need to come up with the appropriate definition for the
alias_method_for method.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.