我有两个独立模型:User
和Invitation
。我正在尝试使用ActiveRecord检查这2个不同表中的条件。
Schema.rb
create_table "invitations", force: :cascade do |t|
t.string "invit_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "provider"
t.string "uid"
t.string "facebook_picture_url"
t.string "first_name"
t.string "last_name"
t.boolean "admin"
t.string "invit_ref"
t.string "invit_one"
t.string "invit_two"
t.string "token"
t.datetime "token_expiry"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
问题:
User.where(:invit_one =>invit_ref)
.or(User.where(:invit_two=>invit_ref))
.or(Invitation.where(:invit_name =>invit_ref)).blank?
我可以单独执行Invitation.where(:invit_name =>invit_ref).blank?
或User.where(:invit_two =>invit_ref).blank?
,但不能将两个表达式组合在一起
不幸的是,我在此简单查询中得到了"PG::UndefinedTable: ERROR: missing FROM-clause entry for table "invitations"
。
您能帮我弄清楚为什么吗?