Reputation: 1161
I have a set of accounts and i want to collect all their id's in a arry so i can use it in a NOT IN operation in a query. Any help would be appreciated, thanks!
@alreadyonteam = @team.accounts.collect { || . }
My query:
@friends = Account.find(current_account.id).active_friends.where('id not in (?)',@alreadyonteam).search(params[:search])
Upvotes: 0
Views: 42
Reputation: 176412
Use pluck
@alreadyonteam = @team.accounts.pluck(:id)
Recent version of Rails also introduce ids
@alreadyonteam = @team.accounts.ids
Upvotes: 2