On Friday, December 20, 2019 at 11:33:21 PM UTC-8, Beth Skurrie wrote:
>
> Thanks Jeremy.
>
> The delay almost works.
>
> DenormalisedOrderLine3.dataset.clone(product_name: "Fish")
> => #<Sequel::SQLite::Dataset: "SELECT * FROM (SELECT `invoice_number`, 
> `product_name`, `customer_id` FROM `orders` LEFT OUTER JOIN (SELECT * FROM 
> `order_lines` WHERE (`product_name` IS NULL)) AS 't1' ON (`t1`.`order_id` = 
> `orders`.`id`)) AS 'orders'">
>
> Unfortunately, the opts aren't picked up in the joined dataset. It works 
> if I delay/clone the joined dataset directly, but then I'm back to not 
> being able to create a class out of it.
>
> DELAYED_ORDER_LINES = DATABASE[:order_lines].where(product_name: 
> Sequel.delay{|ds| ds.opts[:product_name]})
> DELAYED_ORDER_LINES.clone(product_name: "Fish")
> => #<Sequel::SQLite::Dataset: "SELECT * FROM `order_lines` WHERE 
> (`product_name` = 'Fish')">
>

Ah, this is because the subqueries are separate datasets.  I think this 
will fix things, by passing the product_name option to internal datasets 
during the SQL generation process:

DB.extend_datasets do
    def subselect_sql_dataset(sql, ds)
      ds = super
      if product_name = @opts[:product_name]
        ds = ds.clone(product_name: product_name)
      end
      ds
    end
end

Thanks,
Jeremy

-- 
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/c55e1867-3974-4707-92b7-cf1ca3584dd8%40googlegroups.com.

Reply via email to