Demo entry 6714673

eager_load

   

Submitted by anonymous on Feb 15, 2018 at 05:53
Language: Ruby. Code size: 342 Bytes.

class Post < ActiveRecord::Base
    has_many :comments
    has_many :tagged_comments,
      -> { left_joins(:tags).where("tags.name": "Tagged") },
      class_name: "Comment"
  end

  class Comment < ActiveRecord::Base
    belongs_to :post
    has_many :tags
  end

  class Tag < ActiveRecord::Base
    belongs_to :comment
  end

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).