# Newbie Problems with pluralization

**URL:** <https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943>\
**Category:** Rails\
**Created:** [April 16, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943 "2006-04-16T23:08:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 16, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/1 "2006-04-16T23:08:30Z")

</div>

Hi,

I have a many to many relationship incorporating the following tables:

taxes --\> taxes\_tax\_groups --\> tax\_groups

I have a model named tax with the following declaration:

has\_and\_belongs\_to\_many :tax\_groups

and I have a model named tax\_group with the following declaration:

has\_and\_belongs\_to\_many :taxes

I am attempting to run the following unit test:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

class TaxGroupTest \< Test::Unit::TestCase  
fixtures :taxes, :tax\_groups, :taxes\_tax\_groups

# Replace this with your real tests.

def setup  
@taxgroup = TaxGroup.find(1)  
end

# Replace this with your real tests.

def test\_create  
assert\_equal 1, @taxgroup.id  
assert\_equal “Ontario”, @taxgroup.name  
assert\_equal “Ontario w/ pst”, @taxgroup.description  
assert\_equal “GST”, @taxgroup.taxes[1].name  
end  
end

in which i get the following error:

1. Error:  
test\_create(TaxGroupTest):  
ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table  
‘imbibitive\_test.taxes  
\_group’ doesn’t exist: SELECT \* FROM taxes\_group WHERE (taxes\_group.id =
2. LIM  
IT 1  
…  
1 tests, 0 assertions, 0 failures, 1 errors

Should it not pluralize the last work? Or am i missing something here?

Thanks!

---

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 17, 2006, 12:31am UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/2 "2006-04-17T00:31:57Z")

</div>

Hi,

I think, by default, the joint table should be called tax\_groups\_taxes.  
The joint table name is alphabetical and the underscore in tax\_groups  
comes  
before the ‘e’ in taxes.  
At least that’s how I got it to work.

Cheers,  
Andy

---

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 17, 2006, 1:17am UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/3 "2006-04-17T01:17:58Z")

</div>

Thanks for the help!

This now brings up another issue. Rails is pluralizing tax as taxis.

class TaxGroupTest \< Test::Unit::TestCase  
fixtures :taxes, :tax\_groups, :tax\_groups\_taxes

# Replace this with your real tests.

def setup  
@taxgroup = TaxGroup.find(1)  
end

# Replace this with your real tests.

def test\_create  
assert\_equal 1, @taxgroup.id  
assert\_equal “Ontario”, @taxgroup.name  
assert\_equal “Ontario w/ pst”, @taxgroup.description  
assert\_equal “GST”, @taxgroup.taxes[0].name  
end  
end

I complains on the @taxgroup.taxes[0].name line and says:  
const\_missing : uninitialized constant Taxis

Some how it is pluralizing taxes to taxis.

As suggested by another post on this mailing list I have placed this in  
my  
environment.rb:

Inflector.inflections do |inflect|  
inflect.plural ‘tax’, ‘taxes’  
inflect.singular ‘taxes’, ‘tax’

end

When i do that i get an sql error because it changes the tax\_groups  
table name  
in the search to taxes\_group.

test\_create(TaxGroupTest):  
ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table  
‘imbibitive\_test.taxes  
\_group’ doesn’t exist: SELECT \* FROM taxes\_group WHERE (taxes\_group.id =

1. LIM  
IT 1

I’m thinking of turning off the pluralization all together, unless I can  
find a  
fix to this.

Thanks Again!

---

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 17, 2006, 1:36am UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/4 "2006-04-17T01:36:36Z")

</div>

if you start an interactive session using “ruby script\console” you’ll  
find out that ruby correctly pluralizes “tax” to “taxes” without the  
need to explicitly declare that.

---

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 17, 2006, 1:57am UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/5 "2006-04-17T01:57:46Z")

</div>

yeh as above, pluralisation works fine so you don’t need to modify  
environment.rb.

passing class\_name like this:  
has\_and\_belongs\_to\_many :taxes, :class\_name =\> ‘Tax’  
seems to fix it. don’t have time to look into what’s the cause of the  
original problem though.

As suggested by another post on this mailing list I have placed this in  
my

---

<div class="post-metadata">

**Author:** ![Ryan\_Lunde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ryan\_Lunde](https://www.ruby-forum.com/u/Ryan_Lunde)\
**Post date:** [April 17, 2006, 1:54am UTC](https://www.ruby-forum.com/t/newbie-problems-with-pluralization/57943/6 "2006-04-17T01:54:44Z")

</div>

Firstly I didn’t have the problem when I put all the assert tests in  
tax\_test.rb but when I tried it again in tax\_group\_test.rb I got the  
same  
error as you.

I fixed it by passing :class\_name into the habtm declaration in  
tax\_group
