On Wed, Nov 20, 2019 at 1:21 PM Mason Kimble <[email protected]> wrote:
> Basically, can I filter a dataset after it goes to the database?
>
> order_items = OrderItem.dataset.where(order_id: orderId).all (I know this
> would query database)
>
> orders_items_to_match.each { | match_item |
> matching_item = order_items.where(item_id:
> match_item['orderItemId']).first (Does this go back to database or in
> memory)
> }
>
>
I believe you are looking to do the work on the wrong side.
Something like this feels like it would work for you (typos are my middle
name)
# collect items were are searching
item_ids = orders_items_to_match.map { |order_item|
order_item['orderItemId'] }
# query using the items as an IN clause
OrderItem.dataset.where(order_id: orderId).where(item_id: item_ids).all
That should go to the database and select against both the order_id and the
item_ids you are looking for.
John
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/CAPhAwGx-uHn_y84s-YzA9Tb9LZVm1ZJOkso95FH5Ti0GUXtmtA%40mail.gmail.com.