
extlib classify and tableize problems with singular plural inflection exceptions
Reported by Chris Ottrey | August 16th, 2009 @ 11:24 PM | in 0.10.2
The classify and tableize methods have problems with names
ending in words that are exceptions to singular <-> plural
inflection rules.
eg.
'enlarged_testis' <-> 'enlarged_testes'
(NB. something like 'fancy_categories' <-> 'fancy_category' is not an inflection exception, as it follows the '-y' <-> '-ies' rule.)
require 'extlib'
p Extlib::Inflection::classify('fancy_categories'), 'FancyCategory'
p Extlib::Inflection::tableize('FancyCategory'), 'fancy_categories'
p Extlib::Inflection::classify('enlarged_testes'), 'EnlargedTestis'
p Extlib::Inflection::tableize('EnlargedTestis'), 'enlarged_testes'
"FancyCategory"
"FancyCategory"
"fancy_categories"
"fancy_categories"
"EnlargedTeste"
"EnlargedTestis"
"enlarged_testises"
"enlarged_testes"
pull request:
http://github.com/ottrey/extlib/commit/5a989202b31505ff43c630a5ed21...
Comments and changes to this ticket
-
Chris Ottrey August 18th, 2009 @ 11:29 PM
NB. The default "resource_naming_convention" in the AbstractAdapter is UnderscoredAndPluralized,
and that also produces the same errors.p DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('EnlargedTestis') "enlarged_testises" p DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('ComputerMouse') "computer_mouses"
This appears as a problem for models using these special types of names.
eg.
#!/usr/bin/env ruby require 'rubygems' require 'dm-core' class ComputerMouse include DataMapper::Resource property :id , Serial property :name , String belongs_to :manufacturer end class Manufacturer include DataMapper::Resource property :id , Serial property :name , String has n, :computer_mice end
NB. the following will work fine when it creates the database in memory...
DataMapper.setup(:default , "sqlite3::memory:") DataMapper.auto_migrate! hp = Manufacturer.create(:name => 'HP') lo = Manufacturer.create(:name => 'Logitec') p ComputerMouse.create(:name => 'Wireless Mouse', :manufacturer => hp) p ComputerMouse.create(:name => 'Cordless Mouse', :manufacturer => lo) #<ComputerMouse @id=1 @name="Wireless Mouse" @manufacturer_id=1> #<ComputerMouse @id=2 @name="Cordless Mouse" @manufacturer_id=2>
But it fails when using an existing database (because of the inflection problem outlined above).
To create the database use:
cat << EOF | sqlite3 mouse.db CREATE TABLE "computer_mice" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50), "manufacturer_id" INTEGER NOT NULL); CREATE TABLE "manufacturers" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50)); INSERT INTO "manufacturers" ("name") VALUES ('HP'); INSERT INTO "manufacturers" ("name") VALUES ('Logitec'); INSERT INTO "computer_mice" ("name", "manufacturer_id") VALUES ('Wireless Mouse', 1); INSERT INTO "computer_mice" ("name", "manufacturer_id") VALUES ('Cordless Mouse', 2); EOF
then produce the error,
DataMapper.setup(:default , "sqlite3:///#{Dir.pwd}/mouse.db") p Manufacturer.get(1) p ComputerMouse.get(1) #<Manufacturer @id=1 @name="HP"> dm-core/adapters/data_objects_adapter.rb:89:in `execute_reader': no such table: computer_mouses (DataObjects::SyntaxError)
-
Dan Kubb (dkubb) October 7th, 2009 @ 12:51 PM
- Milestone set to 0.10.2
- State changed from new to resolved
- Assigned user set to Dan Kubb (dkubb)
@Chris: I have merged in your branch into the mainline. Thanks for the patch.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »