ruby on rails - Is a migration necessary for generating an ID in a has_many/belongs_to relationship? -


i have rails app 2 related classes. pet has_many toys, , toy belongs_to pet.

in order have index of toys pets (meaning every toy want have index identifier stating pet belongs to), need add migration adding pet_id column each toy (to toys table), or automatically done rails has_many-belongs_to relationship?

you need add pet_id column toys table if table doesn't have one. has_many , belongs_to create methods ease writing code.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -