lib/builder/mongo_helpers.rb in sinatra_resource-0.4.8 vs lib/builder/mongo_helpers.rb in sinatra_resource-0.4.9
- old
+ new
@@ -156,11 +156,12 @@
# @params [String] child_id
#
# @return [MongoMapper::EmbeddedDocument]
def find_child(children, child_id)
raise Error, "children not true" unless children
- children.detect { |x| x.id == child_id }
+ child_id = child_id.to_s
+ children.detect { |x| x.id.to_s == child_id }
end
# Find document with +child_id+ in +children+ or raise 404.
#
# @params [<MongoMapper::EmbeddedDocument>] children
@@ -441,10 +442,12 @@
# @param [Array<MongoMapper::Document>] children
#
# @return [MongoMapper::Document]
def select_related(parent, child_assoc, children)
children.select do |child|
- parent.send(child_assoc).detect { |x| x.id == child.id }
+ parent.send(child_assoc).detect do |x|
+ x.id == child.id
+ end
end
# Note: This has O^2 complexity because of the nesting.
# Can it be done more quickly?
end