Reputation: 1
Looking into passing a variable as value on ActiveRcord query key/column?
login = Login.where("email_address" => "[email protected]","active" => 1).select("id")
=> [#<Login id: 767>]
login = Login.where("email_address" => "[email protected]","active" => 1).select("id").class
=> ActiveRecord::Relation
admin = Admin.where("login_id"=>login).exists?
Heeeelp
Upvotes: 0
Views: 475
Reputation: 118271
You can write as
login_ids = Login.where("email_address" => "[email protected]","active" => 1).pluck(:id)
Admin.where("login_id in (?)", login_ids).blank?
Returns true if relation is blank.
Admin.where("login_id in (?)", login_ids)
gives back us ActiveRecord::Relation
object, so I think we can use #blank?
method.
Upvotes: 2
Reputation: 44685
I would do:
login = Login.where(email_address: '[email protected]', active: 1)
Admin.exists?(login_id: login.pluck(:id))
Upvotes: 2
Reputation: 17834
It should be
admin = Admin.where("login_id" => login.first.id).exists?
Upvotes: 0