Tableize should behave like table_name for namespaced model #3755

tvdeyen opened this Issue Nov 25, 2011 · 2 comments


None yet

2 participants

tvdeyen commented Nov 25, 2011


A namespaced model Alchemy::Page inside an engine.

Rails isolate_namespace Alchemy defines 'alchemy_pages' as table_name.

Calling tableize on an instance of Alchemy::Page returns 'alchemy/pages'

Shouldn't this be equal?


Whether Alchemy::Page.table_name is 'pages' or 'alchemy_pages' depends on the circumstances. In an isolated engine then it has the prefix but if it's a normal module inside an application then it doesn't unless you've added a table_name_prefix method which returns 'alchemy_'. If Alchemy is a model itself then Alchemy::Page.table_name will have the prefix.

As you can see table_name can vary so changing tableize to return 'alchemy_pages' won't always match table_name either. Also given this is a method that's been around since the beginning I would think changing the return signature now would run the risk of breaking apps so I don't think it's a good idea. However I would've thought a pull request with an additional table_name method added to AS::Inflector would be acceptable since it already has a foreign_key method, e.g:

def table_name(class_name)
  tableize(class_name).tr('/', '_')
@pixeltrix pixeltrix closed this Nov 26, 2011
tvdeyen commented Dec 2, 2011

You that should do the trick. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment