ruby on rails - Migration for changing belongs_to association -
i have model called categories belong product i'd them belong store instead. have several thousand of these i'd create migration adds store_id categories , then, gets associated product.store.id it's current association , adds store_id. after i'd remove product association.
does know how , safely achieve that?
should add association in wrong direction, can use change_table reverse association:
class createfavorites < activerecord::migration[5.0] def change create_table :favorites |t| t.belongs_to :article t.timestamps end end end class removearticlefromfavorites < activerecord::migration[5.0] def change change_table :favorites |t| t.remove_references :article end end end class addfavoritetoarticles < activerecord::migration[5.0] def change change_table :article |t| t.belongs_to :favorite end end end
Comments
Post a Comment