0

i'm struggling to make a query that shows the friends of user that have activities in a city. The variable @friends has the friends of the user, and i want to make a join with activities and and places because i want to filter the results by city. A account(user) has many activities and also has many places though activities. I'm having the following error:

SQLite3::SQLException: no such column: accounts.city:

   def show
        @friends = Account.find(current_account.id).active_friends
        @nearbyFriends = @friends.joins(:activities,:places).where(:city => @place.city).group(:account_id)
      end

1 Answer 1

1

Try:

def show
  # ...
  @nearbyFriends = @friends.joins(:activities,:places).where(:places => { :city => @place.city }).group(:account_id)
end

When using joins, any field in where clause must contain table name it comes from. The same applies to group (if friends table doesn't contain account_id).

Sign up to request clarification or add additional context in comments.

3 Comments

SQLite3::SQLException: ambiguous column name: account_id
Which one of your tables contain account_id?
Then as I told you, the same applies to group, so in this case group("activities.account_id").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.