MKK
MKK

Reputation: 2753

Why does it recognize as Unknown Column?

I'm trying to sort ordered by updated_at of User record, which is associated from Code table.

@codes = Code.joins(:user).where('body like ?', "%"+params[:search]+"%").order('user.updated_at DESC').page(params[:page]).per(10)

However, it won't let me sort:(

This is the error message I get.

Error Message

Mysql2::Error: Unknown column 'user.created_at' in 'order clause

Upvotes: 0

Views: 304

Answers (1)

vee
vee

Reputation: 38645

Your database table should be users not user (plural not singular). Update your order method as follows:

order('users.updated_at DESC')

Upvotes: 2

Related Questions