2011-09-15 10 views
0

mongoidへのアクティブなレコードクエリを変換するのを助けてくれますか?複合ActiveRecordからMongoIDクエリ

where(["access_grants.access_token = ? 
AND (access_grants.access_token_expires_at IS NULL 
OR access_grants.access_token_expires_at > ?)", 
conditions[token_authentication_key], Time.now]).joins(:access_grants). 
select("users.*").first 
+0

あなたMongoのコレクションのコレクションがどのように見えるかについての詳細を知る必要があります。私は助けてうれしいです。 – Petrogad

+0

ありがとう、男! plzはプロバイダーのユーザーモデルを見ていますhttp://www.railsatwork.com/2010/10/implementing-oauth-provider-part-1.html - 私はこのコードをモンゴイドに移します –

+0

現在、あなたはあなたのMongoコレクションを持っていますか定義されている?あなたはまだそれらに取り組んでいますか? – Petrogad

答えて

0

すべての感謝、しかし、私はこの問題を解決する方法のレシピを持っている - http://groups.google.com/group/mongoid/browse_thread/thread/7d55c5687479355e

user_id = AccessGrant.where(:access_token => conditions[:token_authentication_key]).any_of({ :access_token_expires_at => nil }, { :access_token_expires_at.gt => Time.now).first.user_id 
user = User.find(user_id)