I have a RoR 4 app, and its model have these associations:has_many :accreditationshas_one :legal, -> { where(kind_cd: Accreditation.legal) }, class_name: 'Accreditation'has_many :departments, -> { where(kind_cd: Accreditation.department) }, class_name: 'Accreditation'So, you see that these associations similar, but legal & departments have more conditions than accreditations. Can I replace class_name: 'Accreditation' with something like using :accreditations?
Rails refactoring has_many
ruby;ruby on rails
I don't see what you will gain with your hypothetical using syntax, let's say there is one... your code will look like this:has_many :accreditationshas_one :legal, -> { where(kind_cd: Accreditation.legal) }, using: :accreditationshas_many :departments, -> { where(kind_cd: Accreditation.department) }, using: :accreditationsHow is it better than your current code? It is not more expressive, nor is it more succinct, nor DRY.Also, these associations are similar to some extent, but they look as DRY as you can make them - one is has_one, while the others are has_many, one uses the default idiom, while the others have names different than the associated class, conditions are different (and though one might argue you can predict the filter by the association name, one is singular, and the other is plural...)In short, I think your current code is good enough - any change will only harm readability.