#1010 ✓resolved
Chris Ottrey

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.

'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'


pull request:

Comments and changes to this ticket

  • Chris Ottrey

    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')
    p DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('ComputerMouse')

    This appears as a problem for models using these special types of names.


    #!/usr/bin/env ruby
    require 'rubygems'
    require 'dm-core'
    class ComputerMouse
      include DataMapper::Resource
      property :id       , Serial
      property :name     , String
      belongs_to :manufacturer
    class Manufacturer
      include DataMapper::Resource  
      property :id       , Serial   
      property :name     , String   
      has n, :computer_mice

    NB. the following will work fine when it creates the database in memory...

    DataMapper.setup(:default , "sqlite3::memory:")
    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);
    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);

    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)

    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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket