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 =
1) 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!
--
Posted via http://www.ruby-forum.com/.
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 On 4/17/06, Ryan Lunde <ryan@b2blogic.net> wrote:> > 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 > 1) 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! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060416/000d7f53/attachment.html
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!
Andy Shen wrote:> 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
>
> On 4/17/06, *Ryan Lunde* <ryan@b2blogic.net
> <mailto:ryan@b2blogic.net>> wrote:
>
> 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 <http://taxgroup.id>
> assert_equal "Ontario", @taxgroup.name
<http://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 > 1) 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!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org>
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
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. -- Posted via http://www.ruby-forum.com/.
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 On 4/17/06, Ryan Lundie <ryan@b2blogic.net> wrote:> > 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! > > Andy Shen wrote: > > 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 > > > > On 4/17/06, *Ryan Lunde* <ryan@b2blogic.net > > <mailto:ryan@b2blogic.net>> wrote: > > > > 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 <http://taxgroup.id> > > assert_equal "Ontario", @taxgroup.name <http://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 > > 1) 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! > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060416/ccd5e0c5/attachment-0001.html
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> > environment.rb: > > > > Inflector.inflections do |inflect| > > inflect.plural ''tax'', ''taxes'' > > inflect.singular ''taxes'', ''tax'' > > > > end > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060416/c83ca659/attachment.html