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

  • Home
  • SEARCH
  • 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 7795869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:11:45+00:00 2026-06-01T23:11:45+00:00

In a Rails(3.2) app, I have a class method on a Model like this:

  • 0

In a Rails(3.2) app, I have a class method on a Model like this:

def import(level, max = 10)
  db = ActiveRecord::Base.connection
  result = db.execute("SELECT word FROM levels WHERE level == #{level} AND word NOT IN (SELECT entry FROM words) limit #{max};");

It just imports 10 new words(create 10 records) at a time that do not exist as Word record yet.

The schema looks something like this:

create_table "levels", :force => true do |t|
  t.string  "word"
  t.integer "level"
end

create_table "words", :force => true do |t|
  t.string  "entry"
  t.integer "level",      :default => 0
  t.text    "definition"
  t.string  "thesaurus",  :default => "none"
end

I’m an SQL noob. Messing with rails dbconsole(sqlite3, I’m using sqlite3 on a server as well), I somehow came up with the raw sql query above. I sort of know that I can do the same thing with Arel. How am I supposed to construct the query with ActiveRecord?

  • 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-01T23:11:46+00:00Added an answer on June 1, 2026 at 11:11 pm

    The following (untested) should work. It uses pluck in the subquery.

    Level.where(:level => level).where("word NOT IN (?)", Word.pluck(:entry)).limit(max)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Action. It looks like this: class Action < ActiveRecord::Base
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to
So I have a Rails app (which in this case seems like it would
In my rails app, i am using a legacy database. class Expression < ActiveRecord::Base
I am developing a Rails v2.3.2 app. I have a Model with validations: class
In my Rails 2.3.2 app I have 2 models: class Post has_many :approved_comments, :class_name
I have a ruby (1.9.3) on rails (3.1) app where: app/models/list.rb class List <
Hi there I have 3 files in rails as follows: 1)Located at app/controller/listings_controller.rb class
I am creating a rails app and have used this code in one of
I have a simple model setup in my Ruby on Rails app. (User {name,

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.