Namespaced Models

It looks like the ActiveRecord and generators namespace conventions are inconsistent. Sometimes the model's table name defaults to 'module_classname' and sometimes to just 'classname.' I'm happy to submit patches and tests, but what is the preferred default?

Example: /script/generate model -t carnivores/tiger name:string

Generator uses table_name 'carnivores_tigers' for fixtures and migrations Base#table_name defaults to 'tigers' Base#table_name rdoc say 'carnivores_tigers'

Granted, this can be fixed by explicitly setting the table name in the model class, but this doesn't seem right.

If the parent is a module, it uses a normal table name.

module Foo   class Bar < ActiveRecord::Base     puts table_name # => 'bars'   end end

class Foo < ActiveRecord::Base   class Bar < ActiveRecord::Base     puts table_name # => 'foo_bars'   end end

I don't know if the generator should be updated, or maybe the docs just need to be clarified a bit.

Thanks -- the intended convention wasn't clear to me. I'm thinking both the generator and the docs need to be updated. The generator interprets 'foo/bar' as module Foo, class Bar, but uses table_name 'foo_bar' for fixtures and migrations.

The Base#table_name docs say: file class table_name invoice/lineitem.rb Invoice::Lineitem invoice_lineitems

But Invoice::Lineitem#table_name returns 'lineitems' for this: class Invoice::Lineitem < ActiveRecord::Base; end

I'm not sure if it's worth spec'ing all the nested module/class/class permutations in the method docs -- we'd be essentially rewriting what's pretty plain in the Ruby code. Maybe an explicit unit test like below would make the intent plain (Contact < Client):

def test_table_name assert_equal 'accounts', MyApplication::Billing::Account.table_name, 'MyApplication::Billing::Account.table_name' assert_equal 'companies', MyApplication::Business::Client.table_name, 'MyApplication::Business::Client.table_name' assert_equal 'company_contacts', MyApplication::Business::Client::Contact.table_name, 'MyApplication::Business::Client::Contact.table_name' end