Skip to content

hypemarks/vesta-activerecord_lateral

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

activerecord_lateral

Let's imagine

class Discussion < ActiveRecord::Base
  belongs_to :topic
end

class Topic < ActiveRecord::Base
  has_many :discussions
  has_many :last_discussions, -> { order(created_at: :desc).limit(3) }, class_name: Discussions
end

Topic.all.includes(:last_discussions) works!

Internals

SELECT "discussions".* FROM (SELECT unnest(ARRAY[2 ,1]) id) ids, LATERAL (SELECT "discussions".* FROM "discussions" WHERE "discussions"."topic_id" = ids.id ORDER BY "discussions"."created_at" DESC LIMIT 3) discussions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%