Here is an example how to do it:
object = Branch.new({"branch_id" => 12312, "branch_name"=> "sample"})
object.users << User.find(1)
object.save
Before the save
you can manipulate what ever you want. It will save the relationship in the correct way.