Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:24:29+00:00 2026-06-18T00:24:29+00:00

I am really new to Rails, but I had some experience with sql, so

  • 0

I am really new to Rails, but I had some experience with sql, so right now I am really struggling with doing a simple thing in rails syntax.

So, there are two tables:

class WorkshopMetadata < ActiveRecord::Base
  attr_accessible :uuid, :action
  belongs_to :workshop
end

class Workshop < ActiveRecord::Base
  has_many :workshop_metadatas
end

And the query I want to do is:

SELECT workshops.*
FROM workshops LEFT JOIN
(SELECT workshop_metadatas.workshop_id as id, workshop_metadatas.uuid 
        FROM workshop_metadatas WHERE uuid = 'smth') as metadatas
WHERE uuid IS NULL

I know that to do left join you have to use includes, but how do I include query, not the table? I am completely baffled by this.

Thank you!

P.S. And while we are at it, are there any good and comprehensive docs for rails? The one that are listing all the available arguments for includes method, for example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:24:30+00:00Added an answer on June 18, 2026 at 12:24 am

    I’d recommend reading through the ActiveRecord query interface guide – it’s a bit verbose, but it’s got a lot of great pointers! For the exhaustive API reference I’d normally point you to http://api.rubyonrails.org/, but it’s pretty bare for ActiveRecord::QueryMethods 🙁 The guide is the best bet…

    Let me rephrase your query to make sure I have it correct: You want to select all workshops that do not have a metadata row with a uuid of smth?

    Thankfully, rails lets you drop down to query fragments, so you should be able to do it via:

    Workshop.joins(
      'LEFT JOIN workshop_metadatas ON workshop_metadatas.workshop_id = workshops.id'
    ).where('uuid IS NULL')
    

    (Isn’t that expressing the same thing w/o the subquery? If not: you should be able to pass your subquery into the joins call)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new to rails and really new to jquery. I've set up some AJAX page
Hi Im new to Ruby On Rails, but have experience building iPhone apps. So
I'm new to rails. I already set up some pages with jekyll. Now I
I'm very new to rails but I really like how easy it is to
I am really new at rails but i was wondering. What is the best
So I'm really new to Rails, and I'm getting a strange error that I
im really new to linq-to-SQL so this may sound like a really dumb question,
I am really new to the programming but I am studying it. I have
I am really really new to Ruby On Rails, so I think it is
I'm very new to rails and attempting to deploy some changes to my production

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.