class Article include DataMapper::Resource property :id, Serial property :name, String has n, :categories, :through => Resource end class Category include DataMapper::Resource property :id, Serial property :name, String has n, :articles, :through => Resource end category_d = Category.new category_d.name = " " category_d.save category_f = Category.new category_f.name = "" category_f.save category_v = Category.new category_v.name = "" category_v.save category_r = Category.new category_r.name = "" category_r.save
article = Article.new article.name = " " article.save category_d = Category.first(:name => " ") category_f = Category.first(:name => "") article.categories << category_d article.categories << category_f article.save
article = Article.first(:name => " ") category_v = Category.first(:name => "") category_r = Category.first(:name => "") category_f = Category.first(:name => "") article.categories = [category_v, category_r, category_f] article.save
Source: https://habr.com/ru/post/201906/
All Articles