jeremyevans/sequel — Issue #394: Eager loading issue
Author: JosephHalter
Created: 2011-11-03 23:03:34+00:00
State: open

Hello,

I've an association defined like this:

master.one_to_one :current_version, class: version, key: :master_id do |ds|
ds.where "created_at<=:now AND (expired_at IS NULL OR expired_at>:now) AND valid_from<=:now AND valid_to>:now", now: Time.now
end

It's coming straight from sequel_bitemporal plugin which I've recently written:

https://github.com/TalentBox/sequel_bitemporal/blob/master/lib/sequel/plugins/bitemporal.rb

I obviously need the block so that Time.now is evaluated at each query. My problem is that I need to:

Master.eager(:current_version).where("current_version.id IS NOT NULL").order(:id).all
Master.eager(:current_version).where("current_version.name ILIKE ?", "%free%").order("current_version.name").all

I'm well aware that eager is not the droid I'm looking for, however if I use eager_graph it ignores the additional condition specified within the association block. I've tried using various options such as :graph_conditions but cannot successfully find how to achieve what I want. Can you please help me?