Make sure it still works if we are working with mongo (use the old code then). We use the class-name so we do not get any issues when Mongoid is not known. Fixes #65.

This commit is contained in:
nathanvda 2012-05-21 00:55:33 +02:00
parent a8a3328ad9
commit 37ab5dd2c5
1 changed files with 9 additions and 3 deletions

View File

@ -86,10 +86,16 @@ module Cocoon
def create_object(f, association) def create_object(f, association)
assoc = f.object.class.reflect_on_association(association) assoc = f.object.class.reflect_on_association(association)
if assoc.collection? if assoc.class.name == "Mongoid::Relations::Metadata"
f.object.send(association).build conditions = assoc.respond_to?(:conditions) ? assoc.conditions.flatten : []
assoc.klass.new(*conditions)
else else
f.object.send("build_#{association}") # assume ActiveRecord or compatible
if assoc.collection?
f.object.send(association).build
else
f.object.send("build_#{association}")
end
end end
end end