Skip to content

Commit

Permalink
Revise string normalisation mechanisms (closes #11 and #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuraga committed Aug 7, 2015
1 parent e46741f commit 9c400a1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/sequel_polymorphic/sequel_polymorphic.rb
Expand Up @@ -17,7 +17,7 @@ def many_to_one(*args, &block)
options ||= {}

if options[:polymorphic]
model = self.to_s.downcase # comment
model = underscore(self.to_s) # comment
plural_model = pluralize(model) # comments

associate(:many_to_one, able,
Expand All @@ -31,7 +31,7 @@ def many_to_one(*args, &block)
able_type = send(:"#{able}_type")
able_id = send(:"#{able}_id")
return if able_type.nil? || able_id.nil?
klass = self.class.send(:constantize, able_type.capitalize)
klass = self.class.send(:constantize, able_type)
klass.where(klass.primary_key => able_id)
end),
:eager_loader => (proc do |eo|
Expand All @@ -43,7 +43,7 @@ def many_to_one(*args, &block)
((id_map[model_able_type] ||= {})[model_able_id] ||= []) << model if !model_able_type.nil? && !model_able_id.nil?
end
id_map.each do |klass_name, id_map|
klass = constantize(klass_name.capitalize)
klass = constantize(camelize(klass_name))
klass.where(klass.primary_key=>id_map.keys).all do |related_obj|
id_map[related_obj.pk].each do |model|
model.associations[able] = related_obj
Expand Down Expand Up @@ -101,7 +101,7 @@ def many_to_many(*args, &block)
able_type = :"#{able}_type"
collection_singular = singularize(collection_name.to_s).to_sym # => tag
collection_singular_id = :"#{collection_singular}_id"
through_klass = constantize(singularize(through.to_s).capitalize) # => Tagging
through_klass = constantize(singularize(camelize(through.to_s))) # => Tagging

associate(:many_to_many, collection_name,
:left_key => able_id,
Expand Down

0 comments on commit 9c400a1

Please sign in to comment.