On Thursday, March 24, 2016 at 10:40:08 AM UTC-7, binarypaladin wrote:
>
> Thing
>   :id
>   :person_id
>   :other_person_id
>
> Person
>   :id
>
> Let's say I want Person :id to match :person_id OR :other_person_id and 
> I'd like to do it without a block so eager graphing still works.
>
> This actually gets me ALMOST all the way there:
>
> Person
>   one_to_many :things, key: [:person_id, :other_person_id], primary_key: 
> [:id, :id]
>
> If I could just replace the AND with an OR this would be perfect and 
> should work if eager graphed. If this functionality doesn't exist, I can 
> probably submit a patch if this is functionality that would be desired.
>

This is pretty easy if you just want to load things for a single object:

Person.one_to_many :things,
  :dataset=>proc{|r| r.associated_dataset.where(id=>[:person_id, 
:other_person_id])}

You can also handling eager graphing fairly easily:

Person.one_to_many :things,
  :graph_block=>proc{|j, lj| {Sequel.qualify(lj, :id)=>[Sequel.qualify(j, 
:person_id), Sequel.qualify(j, :other_person_id)]}},
  :graph_only_conditions=>nil

If you want to do regular eager loading, you'll have to write a custom 
eager loader.

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.

Reply via email to