What I want: for a given foreign key name, and the model class, I can get the association (to know which model it can be resolved to).
For example:
# model: product.rb
class Product < ActiveRecord::Base
belongs_to :category
end
# resolution:
association = Product.get_association('category_id')
So I need this get_association
function.
What I know now:
- from Product.reflections I can get a list of reflections / associations
- for one reflection, I can get the foreign key
- I can build a map for this foreign key, to get the association
However, I want to ask if there is a simple method I can call directly?
Aucun commentaire:
Enregistrer un commentaire