I have a table with two columns employee_id
and manager_id
without the primary key in Mysql. Employee and Employee_Manager have many to many relationships. In order to update the record, I need a primary key on the Employee_Manager
table. Hence, in rails how can generate a migration which adds a column to existing table id(primary key) and set row value for all records in the existing table.
In order to update the record on the association, you don't need an id
column in the table. you can always run a query like below:
EmployeeManager.where(employee_id: 120, manager_id: 75).first.update_attributes(from_date: Time.now)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.