Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

block in assert_valid_keys': Unknown key: :order (ArgumentError)

I'm running rails 4.1.0.rc2 and I'm getting the ArgumentError block in assert_valid_keys': Unknown key: :order when I try to do:

has_many :workout_exercises, dependent: :destroy, order: "exercise_order DESC"`

I want to put an order constraint on my join model, and as far as I can tell, this worked with Rails 3.2, so I can't figure out what is going on. Any ideas?

like image 306
Arel Avatar asked Mar 30 '14 21:03

Arel


2 Answers

Try this:

has_many :workout_exercises, dependent: :destroy,-> { order "exercise_order desc" }

Update, as per OP's comment (reorder the directives):

has_many :workout_exercises,-> { order "exercise_order desc" }, dependent: :destroy
like image 101
Ruby Racer Avatar answered Nov 15 '22 22:11

Ruby Racer


Giving another example that may help those who find this post.

# Rails 3 Syntax (below)
has_one :ca, :class_name => 'C::A',
        :foreign_key => 'person_id',
        :conditions => ['appl_id = ? AND status = ?', 4, 'active']
# Rails 4 Syntax (below) which replaces Rails 3 Syntax (above)
has_one(:ca, -> {where app_id: '4', status: 'active'}, class_name: 'C::A', foreign_key: 'person_id')
like image 35
Chris Avatar answered Nov 15 '22 20:11

Chris