lib/ninja_model/reflection.rb in ninja-model-0.6.2 vs lib/ninja_model/reflection.rb in ninja-model-0.7.0

- old
+ new

@@ -8,17 +8,10 @@ end write_inheritable_hash :reflections, name => reflection reflection end - def ninja_model?(macro, association) - klass = association.to_s.camelize - klass = klass.singularize unless [:has_one, :belongs_to].include?(macro) - klass = klass.constantize - defined?(klass) && klass.ancestors.include?(NinjaModel::Base) - end - def reflections read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {}) end def reflect_on_association(association) @@ -35,11 +28,11 @@ end attr_reader :ninja_model, :name, :macro, :options def klass - @klass ||= class_name.constantize + @klass ||= class_name.camelize.constantize end def class_name @class_name ||= options[:class_name] || derive_class_name end @@ -69,10 +62,11 @@ klass.create!(*options) end def primary_key_name @primary_key_name ||= options[:foreign_key] || derive_primary_key_name + @primary_key_name end def association_foreign_key @association_foreign_key ||= @options[:association_foreign_key] || class_name.foreign_key end @@ -101,10 +95,10 @@ if belongs_to? "#{name}_id" elsif options[:as] "#{options[:as]}_id" else - ninja_model.name.foreign_key + ninja_model.name.demodulize.foreign_key end end end end end