Comments (5)
The patch at http://github.com/dmgr/dm-core/commit/58017d02987e9fdbae23750c3ab1079f47b3e5c5 looks good as it will allow to implement your specific needs in dm-types which probably is a better place then dm-core, like you said on IRC.
by Martin Gamsjaeger (snusnu)
from dm-types.
I created a repo with my custom discriminator types:
http://github.com/dmgr/dmg-types
In the future they can be moved to dm-types if core developers want it.
They will work if you will merge my commit, I prefer this one:
http://github.com/dmgr/dm-core/commit/6af8cab37dfeb7aa1b0230399fddf239e6aac590
by Dawid Marcin Grzesiak
from dm-types.
The commit: http://github.com/dmgr/dm-core/commit/83fba6abcf8bdb2e41371c3d20e78a26950c54dc
will let you do something like this:
require ’rubygems’
require ’datamapper’
DataMapper.setup(:default, "sqlite3::memory:")
class Car
include DataMapper::Resource
property :id, Serial
@brand = property :brand, String
@name = property :name, String
class Ford < self
class Torino < self
end
end
class Audi < self
class TT < self
end
end
def self.discrimination(record)
case record[@brand]
when "Audi" then if ’TT’ == record[@name]
Audi::TT
else
Audi
end
when "Ford" then if ’Torino’ == record[@name]
Ford::Torino
else
Ford
end
else self
end
end
end
p Car.new(:brand => ’Opel’, :name => ’Astra’) #<Car @id=nil @brand="Opel" @name="Astra">
p Car.new(:brand => ’Ford’, :name => ’K’) #<Car::Ford @id=nil @brand="Ford" @name="K">
p Car.new(:brand => ’Ford’, :name => ’Torino’) #<Car::Ford::Torino @id=nil @brand="Ford" @name="Torino">
p Car.new(:brand => ’Audi’, :name => ’TT’) #<Car::Audi::TT @id=nil @brand="Audi" @name="TT">
Additionally default scopes need to be updated in derived classes.
by Dawid Marcin Grzesiak
from dm-types.
Because I need this behavior in my project I had to implement it on v0.10.2 so the solution I use is there:
http://github.com/dmgr/dm-core/tree/my0.10.2
and the code for master branch which I provided before:
http://github.com/dmgr/dm-core
is not the actual one.
by Dawid Marcin Grzesiak
from dm-types.
Yeah, I generally like to hold onto adding new features into the core until there is at least a few people asking for them. Even then I think new features should be put into plugins, and stabilized there. Once it gets enough usage we can talk about moving it into the core.
I would suggest packaging this up into a plugin, and then seeing if there is any interest on the DataMapper mailing list.
by Dan Kubb (dkubb)
from dm-types.
Related Issues (20)
- DataMapper Incomatibilities with rails 3.1 HOT 1
- bcrypt-ruby update HOT 4
- IPAddress Property does not typecast Resolv::IPv4 / Resolv::IPv6 objects HOT 3
- Please update JSON dependency to 1.6.x HOT 7
- dm-types redefines the global CSV constant on Ruby 1.8 HOT 3
- ParanoidBoolean causes issues with belongs_to Relationships HOT 1
- DataMapper::Property::IPAddress attempts to typecase LIKE-queries HOT 5
- UUID: got error on jruby HOT 2
- uninitialized constant ClassName::Enum HOT 3
- Enums are nil when an already created object is fetched HOT 6
- multi-json dependency HOT 1
- Bump stringex dependency to ~>2.0.2 HOT 5
- [release 1.2] rspec failing HOT 1
- Upgrade to safe_yaml
- Exception when assigning an arbitrary string to a Json field
- brcypt-ruby name change HOT 6
- can't modify frozen NilClass HOT 12
- Missing code in release v1.2.2 HOT 3
- UUID missing from migration type map HOT 1
- Update json dependency HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dm-types.