lib/ninja_model/relation.rb in ninja-model-0.5.7 vs lib/ninja_model/relation.rb in ninja-model-0.6.0

- old
+ new

@@ -28,10 +28,16 @@ MULTI_VALUE_ATTRS.each do |v| instance_variable_set("@#{v}".to_sym, []) end end + def new(*args, &block) + scoping { @klass.new(*args, &block) } + end + + alias build new + def to_a @records ||= begin records = @klass.adapter.read(self) @loaded = true records @@ -61,9 +67,20 @@ end alias :inspect! :inspect def inspect to_a.inspect + end + + def scope_for_create + Hash[@predicates.find_all { |w| + w.respond_to?(:meth) && w.meth == :eq + }.map { |where| + [ + where.attribute, + where.value + ] + }] end protected def method_missing(method, *args, &block)