There is a "User" model, in which there is a username field and a dependent Friend model, which contains the username friends. How to get all "not friends"?
@user = User.find_by username: current_user.username - текущий пользователь @users = User.where.not(username: current_user.username) - все пользователи кроме текущего @friends = @user.friends.all - все друзья accordingly, you need to get:
@notfriends = @users - @friends" по полю username I tried this:
@notfriends = @users.where.not(username: @friends.username) Naturally did not work, because:
undefined method `username 'for Friend
How to formulate this subquery so that the call goes not to the object, but to all entities within it?
All that came to mind is a cycle in an action that is passed by a query on all instances of @friends by username .
@friends.each do |friend| @notfriends = @users.where.not(username: friend.username) end However, I would like to do this not with such a structure, but with one request.