Sequel accessing many_to_many join table when adding association
ruby, sequel
Solution
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
Problem
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 sequel chose). The `items_wishlists` table also has an extra column for a facebook id (so I can store opengraph actions), which is a NOT NULL column. I also have `Wishlist` and `Item` models with the sequel many_to_many association set up. The `Wishlist` class also has the `:select` option of the many_to_many association set to `select: [:items.*, :items_wishlists__facebook_action_id]`. Is there a way that I can add in extra data when creating the association, like `wishlist.add_item my_item, facebook_action_id: 'xxxx'` or something? I can't do it after I create the association as the facebook id is has NOT NULL on the column. Thanks for any help