【问题标题】:complex ActiveRecord to MongoID query复杂的 ActiveRecord 到 MongoID 查询
【发布时间】:2011-09-15 11:48:20
【问题描述】:

您能帮我将活动记录查询转换为 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

【问题讨论】:

  • 需要更多地了解您的 Mongo Collection 系列的外观。那我很乐意提供帮助。
  • 谢谢,伙计!请查看提供者的用户模型railsatwork.com/2010/10/implementing-oauth-provider-part-1.html - 我正在将此代码迁移到 mongoid
  • 那么目前您是否定义了 Mongo 集合?还是你还在做那些?

标签: ruby-on-rails-3 activerecord mongodb mongoid


【解决方案1】:

谢谢大家,但我有办法解决这个问题 - 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) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2012-09-01
    • 2011-12-31
    • 2012-11-15
    相关资源
    最近更新 更多