Sequel accessing many_to_many join table when adding association

后端 未结 2 1214
情书的邮戳
情书的邮戳 2021-02-06 12:56

I\'m building a wishlist system using Sequel. I have a wishlists and items table and an items_wishlists join table (that name is what sequ

2条回答
  •  粉色の甜心
    2021-02-06 13:51

    The recommended way to do this is to add a model for the join table. However, if you don't want to do that, you can do:

    class Wishlist
      def _add_item(item, hash={})
        model.db[:items_wishlists].insert(hash.merge(:item_id=>item.id, :wishlist_id=>id))
      end
    end
    

提交回复
热议问题