DEV Community

Discussion on: Help needed in figuring out Rails association

Collapse
 
heraldofsolace profile image
Aniket Bhattacharyea

In the first case user2.networks will give a list of networks he has created, but it seems like the way to go. I can have user2.followed_networks for that. Thanks

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

It's a bit different than you think. user2.networks does only return a list of networks when executed, because networks is not an array. It is an ActiveRecord::Relation. That's why user1.networks.merge(user2.networks) does something completely different than iterating through the networks.

Thread Thread
 
heraldofsolace profile image
Aniket Bhattacharyea

I understand. What I wanted to say was that user2.networks is the list of networks user2 has created, not the ones he's following.