#1226 suggestion
Dawid Marcin Grzesiak

[PATCH] Discriminator type demodulize feature request

Reported by Dawid Marcin Grzesiak | March 27th, 2010 @ 04:00 AM

We all know Discriminator type, but what I wish it to support is some kind of demodulize functionality, let's say:

property :type, Discriminator, :demodulize => true

Normally Discriminator type generate this insert for the code presented in the footer:

INSERT INTO "very_long_module1_very_long_module2_as" ("type") VALUES ('VeryLongModule1::VeryLongModule2::A::A1')

with :demodulize => true options it would be:

INSERT INTO "very_long_module1_very_long_module2_as" ("type") VALUES ('A1')

When you use inheritance in the way I presented below (ie. nested classes), the module A will see and recognize A1 and A2 class, even if you don't prefixe them by "VeryLongModule1::VeryLongModule2::A". I know it could be a problem if you inherit from A class in different Object spaces, in this cases Discriminator needs full path to find them, but it depends on programmer to use it right.

require 'rubygems'
require 'dm-core'
require 'dm-types'

DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')

module VeryLongModule1
  module VeryLongModule2
    class A
      include DataMapper::Resource
     
      property :id, Serial
      property :type, Discriminator # :demodulize => true

      class A1 < self
      end
      
      class A2 < self
      end
    end

    DataMapper.auto_migrate!

    A::A1.new.save
  end
end

Here is a pull request for a path that will open possibility to create custom discriminator types
http://github.com/dmgr/dm-core/commit/58017d02987e9fdbae23750c3ab10...

Comments and changes to this ticket

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 »

Pages