I have three models:

Video

VideoKeyword which has video_id and keyword_id associated to Video and 
Keyword respectively

Keyword

In my Video model, I have:

  one_to_many :related_videos, class: self, dataset: proc { |r|
    kids = keywords_dataset.select(:keyword_id)
    vids = VideoKeyword.distinct(:video_id).
      select(:video_id).
      where(keyword_id: kids)
    Video.where(id: vids)
  }


  one_to_many :keywords, class: 'VideoKeyword',
    order: :start,
    eager: :keyword



related_videos returns all the video that share a common keyword

I'd like to make it work with eager loading, but I'm not sure what is the 
right approach.

-- 
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