Stupid question but I'm not sure why this would work in Rails 4.2 but not in Rails 5.2.
FamilyCharacteristic.where(family_id: @user.family_ids)
.concat(@user.characteristics)
Specs fail in 5.2:
Failure/Error:
FamilyCharacteristic.where(family_id: @user.family_ids)
.concat(@user.characteristics)
NoMethodError:
undefined method `concat' for #<ActiveRecord::Relation []>
Did you mean? count
Was concat removed from ActiveRecord::Relation in 5.2 or was FamilyCharacteristic.where(family_id: @user.family_ids) somehow a different object in < 4.2?
Thanks for any help.
I did some digging and found out that:
FamilyCharacteristic.where(family_id: @user.family_ids)'s class didn't change, it's stillActiveRecord::RelationRelationdidn't and still doesn't define its ownconcatmethod, but it was delegated toArray#concatuntil this commit happened, so in Rails 4.2SomeModel.where(id: ids).concat(some_records)(which returns anArray) was actually the same asSomeModel.where(id: ids).to_a.concat(some_models)ActiveRecord::Delegation, in Rails 5.2, the only methods delegated toArrayare the ones specified in this module andconcatis not among themTo sum up -
concatfrom your example was never part ofActiveRecordbut was delegated toArray#concatand that's why it worked. It's no longer delegated in Rails 5 so it throwsNoMethodError.