Created
July 31, 2009 18:49
-
-
Save macks/159373 to your computer and use it in GitHub Desktop.
Column-level collation support for DataMapper/MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Column-level collation support for DataMapper/MySQL | |
# | |
# e.g.) | |
# property :name, String, :collate => 'utf8_bin' | |
gem 'dm-core', '0.9.11' | |
require 'dm-core' | |
require 'dm-core/adapters/mysql_adapter' | |
module DataMapper | |
module Adapters | |
class DataObjectsAdapter | |
alias property_schema_hash__without_collate property_schema_hash | |
alias property_schema_statement__without_collate property_schema_statement | |
end | |
class MysqlAdapter | |
alias property_schema_hash__without_collate property_schema_hash | |
alias property_schema_statement__without_collate property_schema_statement | |
def property_schema_hash(repository, property) | |
schema = property_schema_hash__without_collate(repository, property) | |
schema[:collate] = property.extra_options[:collate] if property.extra_options.has_key?(:collate) | |
schema | |
end | |
def property_schema_statement(schema) | |
statement = property_schema_statement__without_collate(schema) | |
statement << " COLLATE #{schema[:collate]}" if schema[:collate] | |
statement | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment