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
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:
I think there is also another possibility.
First a MWE (minimal working example) of your question:
To allow
ad_item
with a parameter (Wishlist#add_item(Item.create(descr: 'item 2'), facebook_id: 'fb2')
) you must define anadder
as in this example:The result:
But the next problem will come later:
With
w1.items
you get the list of items, but you have no access to the parameters. (at least I found no way up to now. I'm still researching, but I expect, that I need a model of the join table for this (see Jeremys recommendation))