false do |t| t.integer "tag_id", "page_id" end...">

How to remove rows from connection table using ActiveRecord?

create_table "tags_pages", :id => false do |t|

  t.integer "tag_id", "page_id"

end

add_index "tags_pages", "tag_id"
add_index "tags_pages", "page_id"

How does activerecord work in this table? I want to insert and delete new lines. Sorry if this is a noob question.

+3
source share
1 answer

Suppose you have one page and one tag.

# This will add a "tags_pages" entry, linking one page to one tag
page.tags << tag

# This will delete the appropriate "tags_pages" entry
page.tags.delete(tag)

You can also remove all tags associated with a single page using the method clear.

page.tags.clear
+8
source

Source: https://habr.com/ru/post/1723016/


All Articles