AllenC
AllenC

Reputation: 2754

Getting has_many through models using Rails

I am currently getting has_many relationship associations of a User model using this

User.reflect_on_all_associations(:has_many)

Now, how can I want to get User models with has_many through associations

Upvotes: 1

Views: 129

Answers (1)

Yanis Vieilly
Yanis Vieilly

Reputation: 857

If you only want the has_many :through associations, you can filter your array like this:

User.reflect_on_all_associations(:has_many).select do |association|
  association.options.key? :through
end

Upvotes: 8

Related Questions