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?
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
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With