active record on association create code example
Example 1: rails join table macro
create_join_table :posts, :tags
Example 2: active record dependent destroy
has_many :books, dependent: :destroy
create_join_table :posts, :tags
has_many :books, dependent: :destroy