I have the following models:
User (id, name, network_id)
Network(id, title)
What kind of Rails model assoc do I need to add so that I can do:
@user.network.title
@network.users
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
so network
has_manyusers and a userbelongs_tonetwork.Just add a
network_idto users table if you still haven’t and also since it’s aforeign_keyis worth indexing it.rails generate migration AddNetworkIdToUsersIn the network model do:
In the user model do: