Get objects by bson id
This commit is contained in:
parent
2c1a67eb0f
commit
f4d6a04f4f
2 changed files with 10 additions and 10 deletions
|
|
@ -190,12 +190,13 @@ class User
|
|||
end
|
||||
|
||||
def friend_by_id( id )
|
||||
friends.detect{|x| x.id == id || x.id == BSON::ObjectID(id) }
|
||||
friends.detect{|x| x.id == ensure_bson id }
|
||||
end
|
||||
|
||||
def group_by_id( id )
|
||||
groups.detect{|x| x.id == id || x.id == BSON::ObjectID(id) }
|
||||
groups.detect{|x| x.id == ensure_bson id }
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def assign_key
|
||||
|
|
@ -210,4 +211,11 @@ class User
|
|||
OpenSSL::PKey::RSA::generate 1024
|
||||
end
|
||||
|
||||
def ensure_bson id
|
||||
if id.class == String
|
||||
BSON::ObjectID(id)
|
||||
else
|
||||
id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,3 @@
|
|||
#This file should contain all the record creation needed to seed the database with its default values.
|
||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
||||
# Mayor.create(:name => 'Daley', :city => citie
|
||||
|
||||
require 'config/environment'
|
||||
|
||||
# Create seed user
|
||||
|
|
|
|||
Loading…
Reference in a new issue