Creating has_and_belongs_to_many from legacy data

I’ve just started using rails and I have a legacy DB with 2 models
that have a habtm relationship. I know how to specify the
association, but how do I create the associations from my legacy data?

Thanks,
Jay