On Monday, July 23, 2018 at 7:16:22 AM UTC-7, Arthur Miranda wrote:
>
> Morning, everyone.
>
> I am trying to pass a condition block to a one_to_one association. I
> currently have this:
>
> class User < Sequel::Model
> one_to_many :subscriptions
> end
>
> And I need to get a single active subscription. I thought this would work:
>
> class User < Sequel::Model
> one_to_many :subscriptions
> one_to_one :active_subscription,
> class: :Subscription,
> graph_block: proc{ |j, lj, js| Sequel[j][:ends_at] >= Date.today }
> end
> But no luck, apparently *graph_block* does not work for one-to-one
> associations and is simply discarded.
>
> Is this even possible with Sequel? I know ActiveRecord is capable of doing
> this, but no way I'm switching back to AR over a single feature.
>
:graph_block is only used for eager graphing. For regular and eager
loading, add an association block:
one_to_one ... do |ds|
ds.where{ends_at >= Date.today}
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.