I want to iterate through an array of hash with one key containing an array.
I explain :
- I have a
stores
table - I have a
products
table - I have a
store_exluded_product
table with astore_id
column and aproduct_id
column
I have this array of hashes:
array = [
{ :store_id => 5, :products_ids => [1, 4, 19, 40] },
{ :store_id => 13, :products_ids => [2, 20, 35] },
# ...
]
I want to create new ActiveRecord for my StoreExludedProduct
table like this with StoreExcludedProduct.create()
:
id | store_id | product_id |
---|---|---|
1 | 5 | 1 |
2 | 5 | 4 |
3 | 5 | 19 |
4 | 5 | 40 |
5 | 13 | 2 |
6 | 13 | 20 |
7 | 13 | 35 |
If you have a good solution to my problem which does not make too many DB requests, I would be more than happy
Thank you