I currently have a table userscontaining client_id(so, a User belongs_to :client).
We need to support several customer-related clients, so we have implemented the association User has_and_belongs_to_many :clients. To do this, we:
- created a new table
clients_userswith columns user_idand client_id; - removed
client_idfrom users.
Now, how can we automatically create HABTM entries for each client_idthat we originally had in the table users? We do not want to lose data.
I’m not sure where to start, because I db:migratedon’t have to include models or associations between them, and running raw queries can be difficult in my case.
source
share