Skip to content

Commit

Permalink
normalize _id to id for mongoid
Browse files Browse the repository at this point in the history
  • Loading branch information
timgaleckas authored and ianwhite committed Jun 20, 2012
1 parent d89f25f commit 7ada137
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/orm_adapter/adapters/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Document
module ClassMethods
include OrmAdapter::ToAdapter
end

class OrmAdapter < ::OrmAdapter::Base
# Do not consider these to be part of the class list
def self.except_classes
Expand Down Expand Up @@ -48,7 +48,7 @@ def find_all(options)
def create!(attributes)
klass.create!(attributes)
end

# @see OrmAdapter::Base#destroy
def destroy(object)
object.destroy if valid_object?(object)
Expand All @@ -61,6 +61,8 @@ def conditions_to_fields(conditions)
conditions.inject({}) do |fields, (key, value)|
if value.is_a?(Mongoid::Document) && klass.fields.keys.include?("#{key}_id")
fields.merge("#{key}_id" => value.id)
elsif key.to_s == 'id'
fields.merge('_id' => value)
else
fields.merge(key => value)
end
Expand Down

0 comments on commit 7ada137

Please sign in to comment.