Miguel Morujão
Miguel Morujão

Reputation: 1161

Collect Account ID'S On A Array

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

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176412

Use pluck

@alreadyonteam =  @team.accounts.pluck(:id)

Recent version of Rails also introduce ids

@alreadyonteam =  @team.accounts.ids

Upvotes: 2

Related Questions