私はモンゴイドを使用しており、次のコードがあります。
class Users::User
include Mongoid::Document
field :username, type: String
has_many :emails, class_name: "Users::Email"
end
class Users::Email
include Mongoid::Document
field :email, type: String
belongs_to :user, class_name: "Users::User", inverse_of: :emails
end
データベース:
#users collection
{
"_id" : ObjectId("5162de8a359f10cbf700000c"),
"username" : "bilbo"
}
#emails collection
{
"_id" : ObjectId("5162de8a359f10cbf700000b"),
"email" : "bilbo@jenkins.com",
"user_id" : ObjectId("5162de8a359f10cbf700000c"),
}
次のクエリで検索しようとしています。
Users::User.includes(:emails).any_of({username: login},{"emails.email"=> login}).first
理由はわかりませんが、このクエリはメール関連の検索を無視しています。login = "bilbo"
=> true の場合、ただし= login = "bilbo@jenkins.com"
> nilの場合
それで、私は何を間違っていますか?